nhibernatedetachedcriteria

Restrictions.Disjunction() between condition a AND condition b OR condition c AND condition d


How can I create a disjunction in NHibernate that would accomplish the following sql:

Select * from MyTable
Where (conditionA = true AND conditionB = true)
OR (conditionC = true AND conditionD = true)

From what I've seen, the Disjuntion() takes single criterions and "ORs" them together. Is it possible to group to criterion together and "OR" it against another pair of criterion?

I hope this question is clear enough.

Thanks!


Solution

  • It's not exactly pretty but you would write it like this :

    .Add(
        Restrictions.Or(
            Restrictions.Conjunction().Add(Restrictions.Eq("columnA", true)).Add(Restrictions.Eq("columnB", true)),
            Restrictions.Conjunction().Add(Restrictions.Eq("columnC", true)).Add(Restrictions.Eq("columnD", true))
     );
                                                                    )