NHibernate Lambda 扩展 - CreateCriteria 问题
我想将 NHibernate CreateCriteria 转换为 NHLambdaExtensions 标准,但我收到以下错误我不知道如何修复。
NHibernate 标准如下所示:
var departments = DepartmentService
.CreateCriteria()
.CreateAlias( "Goals", "goal" )
.Add( Expression.Eq( "goal.Company.Id", companyId ) )
.Add( Expression.Eq( "goal.Program.Id", programId ) )
.List<Business.Department>();
我尝试创建的 NHLambdaExtensions 标准如下所示:
Business.Goal goalAlias = null;
var departments = DepartmentService
.CreateCriteria()
.CreateAlias<Business.Goal>( g => g.Department, () => goalAlias )
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();
我收到的错误是“无法解析属性部门:Business.Department”。 该错误显然与“g => g.Department”有关,并且原始 NHibernate 查询中没有任何类似的内容,但没有不采用该表达式的重载。
I want to convert a NHibernate CreateCriteria over to a NHLambdaExtensions criteria, but I'm getting errors that I don't know how to fix.
The NHibernate criteria looks like this:
var departments = DepartmentService
.CreateCriteria()
.CreateAlias( "Goals", "goal" )
.Add( Expression.Eq( "goal.Company.Id", companyId ) )
.Add( Expression.Eq( "goal.Program.Id", programId ) )
.List<Business.Department>();
The NHLambdaExtensions criteria that I'm trying to create looks like this:
Business.Goal goalAlias = null;
var departments = DepartmentService
.CreateCriteria()
.CreateAlias<Business.Goal>( g => g.Department, () => goalAlias )
.Add<Business.Goal>( g => g.Company.Id == companyId )
.Add<Business.Goal>( g => g.Program.Id == programId )
.List<Business.Department>();
The error I'm getting is "Could not resolve property Department of: Business.Department". The error obviously has to do with "g => g.Department", and there is nothing in the original NHibernate query that has something similar, but there are no overloads that don't take the expression.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 NHibernate Lambda 扩展 (V1.0.0.0) - 文档中查找“创建与别名的条件关联”编辑
:
您实际上可以更有效地将其编写为:
Look for "Create Criteria Association With Alias" in NHibernate Lambda Extensions (V1.0.0.0) - Documentation
EDIT:
You can actually write this more efficiently as:
我还没有使用过 NHLambdaExpressions(但它看起来很酷,我一定会很快检查一下),所以我只是在这里猜测。 你能做这样的事情吗:
我认为这将在目标中建立一个新标准,并通过 goalAlias 分配一个别名。
I haven't used NHLambdaExpressions (but it looks pretty cool and I'll definitely check it out soon), so I'm just guessing here. Could you do something like this:
I think this will root a new criteria at Goals and assign an alias via goalAlias.