5

这可能很简单,但我似乎缺乏关于 nhibernate 工作原理的一些知识。这是我的代码:

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>();

我得到的结果错误是:“无法确定来自 (x.FldCurrentFunding / x.FldFundingGoal) 的成员”

4

1 回答 1

2

NHibernate 无法将表达式转换为 sql 语句,因为它不知道如何处理 x.FldCurrentFunding / x.FldFundingGoal。解决方案是将其重写为如下表达式:

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

我希望这会给你一些方向

于 2011-06-23T20:07:58.920 回答