NHibernate Lambda 扩展无法在 DetachedCriteria 上使用任何别名查询
我正在尝试编写一个需要别名的简单查询,因为它是多对多关联,但我无法让它与 NH Lambda 扩展一起使用。它总是给我一个编译错误,尽管据我所知它与文档和我在网上看到的所有示例完全相同。
有效
var query = DetachedCriteria.For<County>()
.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
//.CreateCriteria<County>(x => x.Zips,
// () => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
不起作用
var query = DetachedCriteria.For<County>()
//.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
.CreateCriteria<County>(x => x.Zips,
() => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
生成结果 错误 22 当前上下文中不存在名称“zipAlias”
Intellisense 还突出显示了 CreateCriteria* *
** 说它不理解该方法,但当我在括号内时,它确实正确地显示了参数名称。
I'm trying to write a simple query that requires an alias as it's a Many-To-Many assocation however I can't get it to work with NH Lambda Extensions. It always gives me a compile error even though as far as I can tell it's exactly the same as the documentation and all the examples I've seen online.
Works
var query = DetachedCriteria.For<County>()
.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
//.CreateCriteria<County>(x => x.Zips,
// () => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
Doesn't work
var query = DetachedCriteria.For<County>()
//.CreateCriteria("Zips", "zipAlias", JoinType.LeftOuterJoin)
.CreateCriteria<County>(x => x.Zips,
() => zipAlias, JoinType.LeftOuterJoin)
.Add<Zip>(zip => zip.ZipCode == zipCode);
Results in a build Error 22 The name 'zipAlias' does not exist in the current context
Intellisense also highlights the CreateCriteria**<County>
** saying it doesn't understand the method however it does correctly show me the parameter names when I'm inside the parens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档充满了方便的示例。
您的
zipAlias
需要是本地范围内的变量。由于下载文档链接而不是呈现,我复制了一些部分。
创建与别名的条件关联
使用原始 ICriteria API:
使用 NHibernate Lambda 扩展:
使用别名和连接类型创建条件别名关联
使用原始 ICriteria API:
使用 NHibernate Lambda 扩展:
使用别名和连接类型创建条件关联
使用原始 ICriteria API:
使用 NHibernate Lambda 扩展:
The documentation is full of handy examples.
Your
zipAlias
needs to be a variable in the local scope.As the documentation link downloads instead of rendering, I have copied some sections.
Create Criteria Association With Alias
Using original ICriteria API:
Using NHibernate Lambda Extensions:
Create Criteria Alias Association With Alias And Join Type
Using original ICriteria API:
Using NHibernate Lambda Extensions:
Create Criteria Association With Alias And Join Type
Using original ICriteria API:
Using NHibernate Lambda Extensions: