views:

56

answers:

2

How can I achieve this query using DetachedCriteria:

Select * from 
    MyTable
Where 
    (conditionA = true) or 
    (conditionB = true) or 
    (conditionC = true) or 
    (conditionD = true)
+4  A: 

Like this:

DetachedCriteria.For<MyTable>()
        .Add(Restrictions.Eq("conditionA", true) ||
             Restrictions.Eq("conditionB", true) ||
             Restrictions.Eq("conditionC", true) ||
             Restrictions.Eq("conditionD", true));
asgerhallas
A: 

You can use the Disjunction class like so:

DetachedCriteria.For<MyTable>()
        .Add(Restrictions.Disjunction()
             .Add(Restrictions.Eq("conditionA", true))
             .Add(Restrictions.Eq("conditionB", true))
             .Add(Restrictions.Eq("conditionC", true))
             .Add(Restrictions.Eq("conditionD", true)));
Daniel Auger