Using QueryOver is a bit of a problem because we need to use Projections when using SQL functions.
I dropped abs(...)because it is not necessary becausex * x == -x * -x
1: SqlProjection ( , )
int x = 10;
int y = 20;
var result = session.QueryOver<Product>()
.OrderBy(Projections.SqlProjection(
@"power(x - " + x.ToString() + ", 2) + power(y - " + y.ToString() + ", 2) as tmporder",
new string[] { "test" },
new NHibernate.Type.IType[] { NHibernateUtil.Int32 })).Asc
.List();
2: SqlFunction - :
- ( OperatorProjection , , )
.OrderBy(Projections.SqlFunction("power", NHibernateUtil.Double,
new ArithmeticOperatorProjection("+", NHibernateUtil.Int32,
Projections.Property<Product>(p => p.x), Projections.Constant(x)),
Projections.Constant(2))).Asc
NHibernate OperatorProjection Part 1