How can i query for null values in entity framework?

Posted by AZ on Stack Overflow See other posts from Stack Overflow or by AZ
Published on 2009-03-25T16:46:24Z Indexed on 2010/03/29 20:33 UTC
Read the original article Hit count: 359

Filed under:
|
|

I want to execute a query like this

   var result = from entry in table
                     where entry.something == null
                     select entry;

and get an IS NULL generated.

Edited: After the first two answers i feel the need to clarify that I'm using Entity Framework and not Linq to SQL. The object.Equals() method does not seem to work in EF.

Edit no.2: The above query works as intended. It correctly generates IS NULL. My production code however was

var value = null;
var result = from entry in table
                         where entry.something == value
                         select entry;

and the generated SQL was something = @p; @p = NULL. It seems that EF correctly translates the constant expression but if a variable is involved it treats it just like a normal comparison. Makes sense actually. I'll close this question

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ADO.NET