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?
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 :