如何编写查询子项的 NHibenerate 查询?
我需要编写一个 NHibernate 查询,该查询将限制访问一对多关系中的子项。
例如,我有一个客户对象,其属性是地址列表。我需要找到在给定城市有地址的所有客户。
另外,我编写此查询的方式还包括对客户本身添加其他限制,例如状态、名称等。因此,我不能纯粹从地址角度编写查询。
关于如何实现这一目标有什么想法吗?
I need to write an NHibernate query that will place a restriction that accesses the children in a one to many relationship.
For example, I have a customer object that has property that is a list of addresses. I need to find all customers who have an address in a given city.
Also, I am writing this query in such a way that I will also be adding other restrictions to the customer itself, such as status, name, etc. So, I can't write the query purely from the address perspective.
Any ideas on how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Criteria api,在 Customer 对象的 Adresses 属性上使用“嵌套”条件:
如果您需要查询名称,可以像这样:
You can use the Criteria api, with a "nested" criteria on the Adresses property of your Customer object :
If you need to query on name, you can go like this :