Liqn to sql null-able value in query
Posted
by msony
on Stack Overflow
See other posts from Stack Overflow
or by msony
Published on 2010-03-23T14:47:53Z
Indexed on
2010/03/23
14:53 UTC
Read the original article
Hit count: 353
I need get all items what have no categories
int? categoryId = null;
var items=db.Items.Where(x=>x.CategoryId==categoryId);
this code generate in where:
where CategoryId=null
instead of
where CategoryId is null
ok, when i write
var items=db.Items.Where(x=>x.CategoryId==null);
in my sql profiler it works:
where CategoryId is null
BUT when i do this HACK it doesn't:
var items=db.Items.Where(x=>x.CategoryId==(categoryId.HasValue ? categoryId : null));
so what's the problem? is there by in L2S?
© Stack Overflow or respective owner