2009-09-17 133 views
0

这里是我的LINQ查询:SubSonic3 Linq查询生成 “IS NOT NULL”,而不是 “IS NULL”

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

用户ID是在该部件上表可为空GUID字段对应于ASP.NET成员表aspnet_member。我无法通过subsonic生成一个查询,该查询将选择userid为null的地方,只有它不为null的地方。

这里是我的预期输出:

SELECT Id FROM Member WHERE UserId IS NULL 

这里是我的实际输出:

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

有什么想法?我正在调试过程中,但也许有人遇到了这个问题。

回答

1

原来在VisitBinary方法中没有ExpressionType.Equals的实现。有最近,可以在这里找到一个补丁:

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

旧的代码为:

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; 

的实施增加了对平等。与NotEqual非常相似,除了发出IS NULL而不是IS NOT NULL。