NHibernate 加入和限制标准
我正在尝试编写一个同时有效地加入和限制的 NHibernate 标准。我的数据库看起来像这样......
案例 --->客户产品 <--- 客户 案例 ---->案例状态
每个案例都与一个客户产品相关联(一个产品有多个案例)。
每个客户有多个客户产品(一个客户有多个客户产品)。
每个案例还具有一个案例状态(一个案例状态对应多个案例)。
这已通过 XML 文件进行映射,并且案例和客户之间的多对多解析(通过客户产品)已通过 Sets<> 解决。在 CustomerProduct 映射中,这意味着 CustomerProduct 实体具有以下集合:
Customers
Cases
然后,我创建一个键入为“Cases”的条件。我需要应用的标准是......
状态IN [各种状态代码]。这是通过...实现的。
criteria.Add(Restrictions.In("CaseStatus.CaseStatusId", statuses));
- 实现的
现在我需要仅选择特定客户 ID 的案例。我已经尝试过了...
criteria.Add("CustomerProduct.Customer.CustomerId", customerId);
这不起作用,NHibernate 告诉我它无法解析到 CustomerProduct.Customer.CustomerId 的映射。
Case 具有 CustomerProduct 对象的属性。
CustomerProduct 具有 Customer 对象的属性。
客户拥有 CustomerId 属性。
有什么想法为什么它不起作用吗?
谢谢。
Im trying to write an NHibernate criteria that effectively joins and restricts at the same time. My DB looks like this...
Cases ---> CustomerProducts <--- Customers
Cases ---> CaseStatuses
Each case is associated with a customer product (Many cases to one product).
Each customer has a number of customer products (One customer has many customer products).
Each case additionally has a case status (one case status to many cases).
This has been mapped with XML files and the many to many resolution between cases and customers (through customer products) has been resolved with a Sets<> in the CustomerProduct mapping meaning that the CustomerProduct entity has sets:
Customers
Cases
I then create a criteria typed to "Cases". The criteria I need to apply is....
Statuses IN [varioud status codes]. This has been acheived with....
criteria.Add(Restrictions.In("CaseStatus.CaseStatusId", statuses));
Now I need to select only cases for a specific customer Id. I have tried...
criteria.Add("CustomerProduct.Customer.CustomerId", customerId);
This doesnt work and NHibernate tells me that it cannot resolve the mapping to CustomerProduct.Customer.CustomerId.
Case has a property of a CustomerProduct object.
CustomerProduct has a property of a Customer object.
Customer has a property of CustomerId.
Any ideas why it wont work?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要为 CustomerProduct.Customer 创建一个别名:
我很惊讶 IN 限制在没有别名的情况下工作。这是一篇 好文章 关于使用 Criteria API 执行联接查询。
I think you need to create an alias for CustomerProduct.Customer:
I'm surprised the IN restriction worked without an alias. Here's a good article about performing join queries with the Criteria API.