views:

313

answers:

1

here is my linq query:

 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. I am unable to generate a query through subsonic that will select where the userid IS null, only where it IS NOT 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.

+1  A: 

Turns out there was no implementation for ExpressionType.Equals in the VisitBinary method. 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%5D%5B1%5D

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.

ryanrdl