How can I put List in WHERE for Linq-to-NHiberbnate query if it has nulls in it?
I'm using nHibernate and trying to make query.
Example:
I have List<Entity>
- this will be entities to filter
I have List<int?>
- this will be filter with values of some Entity.SomeId field
this list will contain values: 0,1,2,3,null
I want to make query like this:
List<int?> filters;//1,2,3,null
List<Entity> entities; // some entities
Entities.Where(entity => filters.Contains(Enentity.SomeId)).ToList();
nHibernate makes query(kind of):
select * from entities where 开发者_如何学编程entity.someId in (....);
result: returned all filtered records i need except entities where entity.SomeId == null
What's wrong with it? is there some workaround for such stuff?
I would use a compound condition and use a list of int
instead of int?
.
List<int> filters;//1,2,3
List<Entity> entities; // some entities
Entities.Where(entity => entity.SomeId == null
|| filters.Contains(Enentity.SomeId))
.ToList();
精彩评论