views:

34

answers:

1

Each Store has many Products.

Store --> (N) Products

How to create an NHibernate criteria to get stores with more than 2 products which price is greater than 2.0$ ?

I know how to get Stores based on a criteria on Products and I also know how to get the count of Products which Price is greater than 2, but I can't find a way to put a criteria on the count.

+2  A: 

You're looking for a DetachedCriteria - it lets you run a subquery - in your case, the number of products whose price is greater then $2, then us it as a criteria.

https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querycriteria.html#querycriteria-detachedqueries

Ofir