Dividing using nhibernate results in "Could not determine member from"

1.3k Views Asked by At

This is probably something simple but I seem to be lacking some knowledge of how nhibernate works. This is my code:

ICriteria query = Session.CreateCriteria<TblProjectCategory>();
query = query.CreateCriteria<TblProjectCategory>(x => x.TblProjects)
    .Add<TblProject>(x => x.FldCurrentFunding != 0m)
    .Add<TblProject>(x => x.FldCurrentFunding / x.FldFundingGoal >= .8m)
    .SetResultTransformer(
        new NHibernate.Transform.DistinctRootEntityResultTransformer());

return query.List<TblProjectCategory>();

The resulting error I get is: "Could not determine member from (x.FldCurrentFunding / x.FldFundingGoal)"

1

There are 1 best solutions below

0
On

NHibernate is not able to translate the expression into a sql statement because is does not know what to do with x.FldCurrentFunding / x.FldFundingGoal. The solution is rewriting this to an expression like:

ISQLFunction sqlDiv = new VarArgsSQLFunction("(", "/", ")");
(...)
   .Add(
    Expression.Ge(
        Projections.SqlFunction(
            sqlDiv, 
            NHibernateUtil.Double,
            Projections.Property("FldCurrentFunding"),
            Projections.Property("FldCurrentGoal")
        ),
        0.8m 
    )
    )
(...)    

I hope this will give you some directions