Say I have an SQL query that needs to be executed using nHibernate. The SQL WHERE clause consists of three OR statements, each of which contains a list of conditions. For instance:
SELECT * FROM MyTable WHERE (OrderId = 1 and ItemId = 100) OR (OrderId = 2 and ItemId = 200) OR (OrderId = 3 and ItemId = 300)
Using the nHibernate Criteria syntax, I could use a disjunction to implement this:
var disjunction = Restrictions.Disjunction(); foreach (var tuple in OrdersAndLineItems) { var conjunction = Restrictions.Conjunction(); var order = tuple.Item1; var lineitem = tuple.Item2; conjunction.Add(Restrictions.Eq("OrderId", order.Id)); conjunction.Add(Restrictions.Eq("LineItemId", lineitem.Id)); disjunction.Add(conjunction); } var result = Session.CreateCriteria<SomeClass>().Add(disjunction).ToList();
How to write the same type of query using the QueryOver syntax in nHibernate 3.x?
source share