问题列表 - 第49610页

实体框架自动生成的表名

使用实体框架通常会编写诸如的查询

var orders = from o in context.Orders.Include("Customer")
             where o.OrderDate.HasValue && o.OrderDate.Value.Year == 1997
             orderby o.Freight
             select o;
Run Code Online (Sandbox Code Playgroud)

真正让我的胃流失的是"Customer"字符串论证.我很难相信EF不会在某处生成表名作为常量.有没有人知道比使用字符串更好的方法?对于Include获取选项?

c# entity-framework

5
推荐指数
1
解决办法
579
查看次数

循环中的异步性

我正在使用jQuery的$.getJSON()API从给定的URL中检索一组实用程序的数据.我真的想找到一种方法来重用每个实用程序的代码(它们都完全相同).由于循环正在执行而不考虑ajax调用,因此我无法找到保留循环值的方法.

我知道,那个描述很糟糕,所以这里是一个代码片段,它将它定义得更好一些:

var utility_types = [ 'Electricity', 'Gas', 'Water' ];

/** Retrieve known utility providers for the given zip code */
for( var i = 0; i < utility_types.length; i++ ) {
  var type = utility_types[i];

  $.getJSON( '/addresses/utilities/' + zip + '/' + type + '.json', null, function( data, status ) {
    alert( 'Processing ' + type );
  });
}
Run Code Online (Sandbox Code Playgroud)

我需要找到一种方法将类型值传递给回调,以便我可以应用正确的语法.没有它,所有3个循环都在针对"Water"实用程序执行.我知道为什么它工作,我只是想知道是否有一个合理的解决办法.

谢谢.

ajax jquery

5
推荐指数
1
解决办法
176
查看次数

PHP会话变量未设置

我遇到了PHP会话变量的问题:我尝试设置变量,即使在同一个文件中也不能读取它们,更不用说另一个文件了.

很抱歉,如果之前已经问过这个问题,但我找不到任何不说"确保你session_start()在文件开头就有"的问题.

文件的第1,2和3行:

<?php
    ini_set('session.save_path','/home/[username]/session_data'); // Just in case, points to a correct directory
    session_start();
Run Code Online (Sandbox Code Playgroud)

之后,在用户名验证和登录之后,变量被设置,代码会尝试echo输出:

$_SESSION['login'] == "true";
$_SESSION['username'] == $username;
$_SESSION['password'] == sha1($password);
//header("Location: [admin page hidden]"); // Code would normally redirect to admin page (commented out for debugging), and exit
//exit;
echo "Username: ".$username."<br />"; // The following 4 lines try to print out the data
echo "Password: ".$password."<br />";
echo "Secure Password: ".sha1($password)."<br />";
echo "Session Username: ".$_SESSION['username']."<br />";
Run Code Online (Sandbox Code Playgroud)

输出是:

Username: root …
Run Code Online (Sandbox Code Playgroud)

php session

2
推荐指数
1
解决办法
4490
查看次数

让Ninject管理我的交易状态,实践问题

我让Ninject管理我ISessionITransaction状态良好nHibnerate与下列注册方法-我想知道,如果它是交易的足够的控制,或者我是否需要别人把这个地方.

我们的想法是每个ISession都是在请求上创建的,并且Ninject处理在该请求期间完成的所有操作的提交.

public class SessionModule : Ninject.Modules.NinjectModule
{
    private static ISessionFactory sessionFactory;

    public override void Load()
    {
        Bind<ISessionFactory>()
            .ToMethod(c => CreateSessionFactory())
            .InSingletonScope();

        Bind<ISession>()
            .ToMethod(c => OpenSession())
            .InRequestScope()
            .OnActivation(session =>
            {
                session.BeginTransaction();
                session.FlushMode = FlushMode.Commit;
            })
            .OnDeactivation(session =>
            {
                if (session.Transaction.IsActive)
                {
                    try
                    {
                        session.Flush();
                        session.Transaction.Commit();
                    }
                    catch
                    {
                        session.Transaction.Rollback();
                    }
                }
            });
    }

    /// <summary>
    /// Create a new <see cref="NHibernate.ISessionFactory"/> to connect to a database.
    /// </summary>
    /// <returns>
    /// A constructed and …
Run Code Online (Sandbox Code Playgroud)

nhibernate ninject

11
推荐指数
1
解决办法
1285
查看次数

使用UNIQUE约束Postgres在一个字段中增加一组值

我有一个表,其中我有一个数字字段A,它被设置为UNIQUE.该字段用于指示必须执行某些操作的顺序.我想对所有更大的值进行更新,例如,超过3.例如,我有

A     
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)

现在,我想为A大于3的所有值添加1.所以,结果就是

A     
1
2
3
5
6
Run Code Online (Sandbox Code Playgroud)

问题是,是否可以只使用一个查询来完成?请记住,我对A列有一个UNIQUE约束.

显然,我试过了

UPDATE my_table SET A = A + 1 WHERE A > 3;
Run Code Online (Sandbox Code Playgroud)

但它不起作用,因为我对这个领域有约束.

sql postgresql sql-update

8
推荐指数
2
解决办法
7894
查看次数

在Clojure重写Lisp土地的向导游戏

我正试图从"Land of Lisp"重写向导游戏 http://landoflisp.com/wizards_game.lisp

(def *nodes* {:living-room "you are in the living-room. a wizard is snoring loudly on the couch."
          :garden "you are in a beautiful garden. there is a well in front of you."
          :attic "you are in the attic. there is a giant welding torch in the corner."})

(def *edges* {:living-room '((garden west door) (attic upstairs ladder))
          :garden '(living-room east door)
          :attic '(living-room downstairs ladder)})

(defn describe-location [location nodes]
  (nodes location))

(defn describe-path-raw [edge]
  `(there is a ~(last …
Run Code Online (Sandbox Code Playgroud)

lisp jvm clojure land-of-lisp

9
推荐指数
1
解决办法
1099
查看次数

在MATLAB中,我可以在同一个文件中有脚本和函数定义吗?

假设我有一个函数f(),我想使用它my_file.m,这是一个脚本.

  1. 是否可以定义函数my_file.m
  2. 如果没有,假设我已经定义了它f.m.我怎么称呼它my_file.m

我阅读了在线文档,但目前尚不清楚最佳方法是什么.

matlab file function

78
推荐指数
5
解决办法
10万
查看次数

简单的Haskell实例问题

我正在尝试不同的数据结构来实现Prim的算法.所以我创建了一个类来抽象我想要做的事情:

class VertexContainer a where
  contains :: a -> Vertex -> Bool
  insert :: a -> WeightedEdge -> a
  numVertices :: a -> Int
Run Code Online (Sandbox Code Playgroud)

现在我想使用堆(from Data.Heap)作为我的顶点容器.但我不能为我的生活弄清楚语法.从insert声明中可以看出,容器只能包含WeightedEdges,这是一种数据类型.所以我尝试过:

instance VertexContainer (Heap MinPolicy WeightedEdge) where
  contains _ _ = True
Run Code Online (Sandbox Code Playgroud)

它告诉我这是一个非法类型的同义词.我尝试了其他各种排列,但似乎都没有.谁能帮我?

haskell

3
推荐指数
1
解决办法
197
查看次数

RabbitMQ用什么语言编写?

我正在看repos,有很多项目,不确定哪些是包装器/客户端,哪个是实际项目.

是Erlang吗?

rabbitmq

9
推荐指数
1
解决办法
3656
查看次数

使用Moose的Perl OO - 编写委派示例的最佳方法?

Perl的Moose与其他对象系统不同,因此并不总是清楚如何将其他语言中已知的示例翻译成Moose术语.考虑下面的Rectangle和Square的Java示例,其中Square实例(一个正方形是一个特殊的矩形)将对area()的调用委托给它持有私有引用的Rectangle实例.

package geometry;
class Rectangle {
    private int x;
    private int y;
    public Rectangle(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public int area() {
        return x * y;
    }
}
class Square {
    private Rectangle rectangle;
    public Square(int a) {
        this.rectangle = new Rectangle(a, a);
    }
    public int area() {
        return this.rectangle.area();
    }
}
public class Main {
    public static void main( String[] args ) {
        int x, y;
        if ( args.length > 1 ) …
Run Code Online (Sandbox Code Playgroud)

perl delegation moose

6
推荐指数
2
解决办法
3161
查看次数