5 nhibernate nhlambdaextensions
这可能很简单,但我似乎缺乏一些关于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>();
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:"无法从(x.FldCurrentFunding/x.FldFundingGoal)确定成员"
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
)
)
(...)
Run Code Online (Sandbox Code Playgroud)
我希望这能给你一些指导
| 归档时间: |
|
| 查看次数: |
1196 次 |
| 最近记录: |