Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

03/04/2009 LINQ Queries Containing Null Values for Nullable in a Where Clause
Posted by Osvel Legon

How does LINQ to SQL handle the nullable type in the where clause?

The current .Where expression does not support the use of == between Nullable types when there is a null value, so here it's a trick to solve that:

Use object.Equals to get 2-value equals semantics (nulls equal nulls).

from c in db.ProductCategories
where object.Equals(c.ParentProductCategoryID, myID)
select c;

If the compared value is null LINQ will generate c.ParentProductCategoryID IS NULL otherwise it will generate c.ParentProductCategoryID = myID.

« Back to Blog Main Page |

0 Comment(s)

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy