Question

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.

Was it helpful?

Solution

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][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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top