开发者

Nhibernate: restriction with sum of 2 columns

Can I create this sql query using HNibernate Criteria:

开发者_JS百科

Select * from Table1 where Column1 > (Column2 + Column3)

All 3 columns are int32. Thanks


Well, after reading for the n-th time a question with this exact problem i decided to write an implementation that doesn't include writing SQL.

You can check the implementation at http://savale.blogspot.com/2011/04/nhibernate-and-missing.html with which you can write:

criteria.Add(
   Restrictions
     .GeProperty("Prop1",
                 new ArithmeticOperatorProjection("+",
                                 NHibernateUtil.Int32,
                                 Projections.Property("Prop2"), Projections.Property("Prop3")
                                                  )
                )
);


You can use an Expression and write some SQL, that's what works for me.

criteria.Add(Expression.Sql("Column1 > (Column2 + Column3)"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜