代码之家  ›  专栏  ›  技术社区  ›  Roman

带3个或多个条件的分离条件

  •  1
  • Roman  · 技术社区  · 14 年前

    Select * from 
        MyTable
    Where 
        (conditionA = true) or 
        (conditionB = true) or 
        (conditionC = true) or 
        (conditionD = true)
    
    2 回复  |  直到 14 年前
        1
  •  3
  •   Daniel Auger    14 年前

    可以这样使用析取类:

    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)));
    
        2
  •  5
  •   asgerhallas    14 年前

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