应该如何用Nhibernate的iCriteria api编写以下查询:

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

我需要的是将表达式(property1 + propert2)与给定值进行比较(cresence.ammount)。

我正在使用NHibernate 2.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")
    )
)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top