R – NHibernate query for object with child collection property

criteriahqlnhibernate

I need help with an nhibernate query. I would prefer to use Criteria API if possible, otherwise HQL is ok.

I have an Employee object with an Account object property, the Account has a collection of Entry objects, and each Entry has an Amount property.

I need a query that will return all employees who have an account where the sum of the Entry.Amount is less than zero.

Any ideas?

Best Answer

As shown here:

ICriteria.CreateCriteria(typeof(Customer))
.Add(Expression.Eq("Firstname", "Steve"))
.CreateCriteria("Orders")
.Add(Expression.Gt("OrderDate", new  Datetime.Now)))
.List<Customer>();