具有3个OR条件的DetachedCriteria

时间:2010-08-03 06:20:11

标签: nhibernate fluent-nhibernate

如何使用DetachedCriteria实现此查询:

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

2 个答案:

答案 0 :(得分:5)

像这样:

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

答案 1 :(得分:3)

您可以像这样使用Disjunction类:

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)));