如何构造nHibernate QueryOver(X和Y)OR(null AND null)

时间:2016-09-29 13:07:11

标签: linq nhibernate queryover

在SQL ease中:

where (Id1 = @iX and Id2 = @iY) OR (id1 is null AND Id2 is null)

In(sudo / failed)nHibernate:

where (c => c.Id1 == iX AND c.Id2 == iY) OR (c => c.Id1 == null AND c.Id2 == null)

所有有用的建议表示赞赏。

1 个答案:

答案 0 :(得分:0)

使用标准:

        var r = ses.CreateCriteria<myT>()
            .Add(Restrictions.Or(
                Restrictions.And(Restrictions.Where<myT>((c) => c.Id1 == iX)
                    , Restrictions.Where<myT>((c) => c.Id2 == iY)
                )
                , Restrictions.And(Restrictions.Where<myT>((c) => c.Id1 == null)
                    , Restrictions.Where<myT>((c) => c.Id2 == null)
                )
            ))
            .List<myT>();

网是合理的:

WHERE ((this_.Id1 = @p0 and this_.Id2 = @p1) or (this_.Id1 is null and this_.Id2 is null))

其中@ p0 = @iX和@ p1 = @iY