Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where ... In ... Or Where ... In ... with NHibernate IQueryOver

I'm trying to emulate subject query with NHibernate's IQueryOver. So far I have

var q = CurrentSession.QueryOver<ObjectModel.Order>().
    WhereRestrictionOn(o => o.Buyer.ID).IsIn(partyIDs).
    WhereRestrictionOn(o => o.Seller.ID).IsIn(partyIDs);

This, however, generates an and query, whereas I need to have an or operator between two where clauses.

How is this done with IQueryOver?

like image 983
Anton Gogolev Avatar asked May 16 '11 15:05

Anton Gogolev


1 Answers

As it usually is, found question soon after explaining the problem to general public. Thanks, guys!

var q = CurrentSession.QueryOver<ObjectModel.Order>();

q.RootCriteria.Add(Restrictions.Or(
    Restrictions.On<ObjectModel.Order>(o => o.Buyer.ID).IsIn(partyIDs),
    Restrictions.On<ObjectModel.Order>(o => o.Seller.ID).IsIn(partyIDs)));
like image 85
Anton Gogolev Avatar answered Oct 08 '22 19:10

Anton Gogolev