문제

How should be written the following query with the NHibernate's ICriteria API:

DetachedCriteria criteria = DetachedCriteria.For<Order>()
    .Add(Restrictions.Eq("Property1 + Property2", confirmation.Ammount));

What I need is to compare an expression (Property1 + Property2) to given value (confirmation.Ammount).

I'm using NHibernate 2.0 (I can't switch to newer version at the moment).

Thanks

도움이 되었습니까?

해결책

option 1

.Add(Expression.Sql("(Property1 + Property2) = ?", confirmation.Ammount, NHibernateUtil.Int32));

option 2

writing your own Projection see here

.Add(Restrictions.Eq(new ArithmeticOperatorProjection(
    "+", NHibernateUtil.Int32, Projections.Property("Property1"), Projections.Property("Property2")
    )
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top