c# - Nhibernate empty query -
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 equipment
but nhibernate can't build expression tree item => false
. someday expression change, must return empty query. there method solve problem?
assuming 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 iqueryover not iqueryiable, had @ source , queryover protected can't see how create empty 1 right now. suggestion use linq provider if can original answer work. if it's not possible ugly hack work 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);
Comments
Post a Comment