Is there a way in Nhibernate to query with an optional where clause.
I have a query below with a list of Ids passed in:
var query = Session.QueryOver<Orders>()
.WhereRestrictionOn(x => x.OrderId)
.IsIn(Ids);
If the list is empty I would like to return the whole Orders table. Is this possible to do this using NHiberbate?
Just do this:
var query = Session.QueryOver<Orders>();
if (ids == null || ids.Count == 0)
{
query = query.WhereRestrictionOn(x => x.OrderId).IsIn(Ids);
}