简体   繁体   English

SubSonic3 Linq查询生成“ IS NOT NULL”而不是“ IS NULL”

[英]SubSonic3 Linq query generates “IS NOT NULL” instead of “IS NULL”

here is my linq query: 这是我的linq查询:

 var test = from m in db.Members where m.UserId == null select m.Id;
        test.ToList();

UserId is a nullable Guid field on the members table that corresponds to the ASP.NET membership table aspnet_member. UserId是成员表上与ASP.NET成员资格表aspnet_member对应的可为空的Guid字段。 I am unable to generate a query through subsonic that will select where the userid IS null, only where it IS NOT null. 我无法通过subsonic生成查询,该查询将选择用户ID为null的位置,仅选择用户ID不为null的位置。

here is my expected output: 这是我的预期输出:

 SELECT Id FROM Member WHERE UserId IS NULL

here is my actual output: 这是我的实际输出:

 SELECT Id FROM Member WHERE UserId IS **NOT** NULL

Any thoughts? 有什么想法吗? I am in the processes of debugging but maybe someone else has run into this. 我正在调试过程中,但也许有人遇到了这个问题。

Turns out there was no implementation for ExpressionType.Equals in the VisitBinary method. 事实证明,VisitBinary方法中没有ExpressionType.Equals的实现。 There was recently a patch that can be found here: 最近有一个补丁,可以在这里找到:

[ http://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Linq/Structure/TSqlFormatter.cs][1] [ http://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Linq/Structure/TSqlFormatter.cs][1]

The old code was: 旧代码是:

case ExpressionType.Equal:
case ExpressionType.NotEqual:
    if (right.NodeType == ExpressionType.Constant)
                {
                    ConstantExpression ce = (ConstantExpression)right;
                    if (ce.Value == null)
                    {
                        this.Visit(left);
                        sb.Append(" IS NOT NULL");
                        break;
                    }
                }
                else if (left.NodeType == ExpressionType.Constant)
                {
                    ConstantExpression ce = (ConstantExpression)left;
                    if (ce.Value == null)
                    {
                        this.Visit(right);
                        sb.Append(" IS NOT NULL");
                        break;
                    }
                }
                goto case ExpressionType.LessThan;

The implementation has been added for Equal. 该实现已添加为等于。 Is is pretty much identical to NotEqual except emits IS NULL instead of IS NOT NULL. 除了发出IS NULL而不是IS NOT NULL之外,Is与NotEqual几乎相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM