Reputation: 264
I have next code
if (user != null)
query = query.Where(item => item.User.Id == user.Id);
else if (equipment != null)
query = query.Where(item => false);// TODO: Add logic for equipment
but NHibernate can't build expression tree for item => false
. Someday this expression will change, but now it must return empty query. Is there some method to solve this problem?
Upvotes: 0
Views: 1366
Reputation: 6379
Assuming it is an IQueryable of User, try this.
if (user != null)
query = query.Where(item => item.User.Id == user.Id);
else if (equipment != null)
query = new List<User>().AsQueryable();
Edit:
OP said it is a IQueryOver not an IQueryiable, had a look at source and QueryOver is protected so can't see how to create an empty one easily right now. My suggestion is to use the LINQ provider if you can so my original answer will work. If it's not possible then this UGLY hack will work for now.
if (user != null)
query = query.Where(item => item.User.Id == user.Id);
else if (equipment != null)
query = query.Where(item => item.User.Id < 0 && item.User.Id > 1);
Upvotes: 1