문제

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top