Nhibernate 表达限制

Nhibernate 表达限制,nhibernate,icriteria,Nhibernate,Icriteria,应如何使用NHibernate的ICriteria API编写以下查询: DetachedCriteria criteria = DetachedCriteria.For<Order>() .Add(Restrictions.Eq("Property1 + Property2", confirmation.Ammount)); DetachedCriteria=DetachedCriteria.For() .Add(Restrictions.Eq(“Property1+Pr

应如何使用NHibernate的ICriteria API编写以下查询:

DetachedCriteria criteria = DetachedCriteria.For<Order>()
    .Add(Restrictions.Eq("Property1 + Property2", confirmation.Ammount));
DetachedCriteria=DetachedCriteria.For()
.Add(Restrictions.Eq(“Property1+Property2”,confirmation.amount));
我需要的是将表达式(Property1+Property2)与给定值(confirmation.amount)进行比较

我正在使用NHibernate2.0(目前无法切换到新版本)

谢谢

选项1

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

写你自己的投影

.Add(Restrictions.Eq(new ArithmeticOperatorProjection(
    "+", NHibernateUtil.Int32, Projections.Property("Property1"), Projections.Property("Property2")
    )
)