NHibernate 对一个类的 2 个以上连接字段进行排序
我想问一下如何对具有 2 个属性(基本上由 2 个实体连接)的对象进行排序。
假设“ClassA”有一个名为 ClassB 和 ClassC 的属性,它们本身也是类。 ClassB 有一个名为 Name 的属性,ClassC 也有一个名为 Name 的属性。现在,由于 ClassB 和 ClassC 都是 ClassA 的属性,我如何使用 ClassB 和 ClassC 的 Name 属性来排序 ClassA 列表。下面是 C# 中的 NHibernate 标准代码示例:
ICriteria criteria = m_Session.CreateCriteria<ClassA>()
.AddOrder(Order.Asc("ClassB.Name"))
.AddOrder(Order.Asc("ClassC.Name"));
但是上面的代码会抛出一个错误: “无法解析属性:ClassB。名称:ClassA”。任何帮助将不胜感激。多谢。
I would like to ask on how you do ordering on an object with 2 properties that are basically joined from 2 entities.
Lets say "ClassA" has a property named ClassB and ClassC which are also classes themselves. ClassB has a property named Name and ClassC also has a property named Name. Now, since ClassB and ClassC are both properties of ClassA, how can i order a list of ClassAs using the Name properties of ClassB and ClassC. Below is the sample NHibernate criteria code in C#:
ICriteria criteria = m_Session.CreateCriteria<ClassA>()
.AddOrder(Order.Asc("ClassB.Name"))
.AddOrder(Order.Asc("ClassC.Name"));
But the above code throws an error saying that
"could not resolve property: ClassB.Name of: ClassA". Any help would be appreciated. Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为 2 个关联(ClassB 和 ClassB)指定别名,以便可以按它们进行排序。
You will need to alias the 2 associations (ClassB & ClassB) so that you can order by them.