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

This is probably something simple, but it seems that I lack 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>();

As a result, an error occurs: "Failed to determine the member from (x.FldCurrentFunding / x.FldFundingGoal)"

+5
source share
1 answer

NHibernate cannot convert an expression to an sql statement because it does not know what to do with x.FldCurrentFunding / x.FldFundingGoal. The solution rewrites this expression like this:

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

Hope this gives you a few directions.

+2
source

All Articles