Nhibernate: 2 column limit

Is it possible to create this sql query using HNibernate Criteria:

Select * from table 1, where Column1> (Column2 + Column3)

All 3 columns are int32. Thanks

+3
source share
2 answers

Well, after reading the question for the nth time with this exact problem, I decided to write an implementation that does not include an SQL record.

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")
                                                  )
                )
);
+4
source

You can use Expressionand write some SQL, which is what works for me.

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

All Articles