Where ... In ... Or Where ... In ... with NHibernate IQueryOver
Asked Answered
N

1

8

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?

Natividadnativism answered 16/5, 2011 at 15:27 Comment(0)
N
9

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)));
Natividadnativism answered 16/5, 2011 at 15:32 Comment(2)
you can check this too Anton queryover and (x like 'a' or y like 'a')Sarraceniaceous
@Burn Well worth a separate answer. Thanks!Natividadnativism

© 2022 - 2024 — McMap. All rights reserved.