NHibernate query for object with child function

I need help with nhibernate query. I'd rather use the criteria API if possible, otherwise the HQL is fine.

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

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

Any ideas?

+2


source to share


2 answers


In case it helps ... This issue was solved with Named Query. Not sure if this is possible with the criteria API.

request:



select employee.* from employee
join (
    select accountid, sum(amount) as balance
    from entry group by accountid
) as accountbalances on accountbalances.accountid = employee.account
where accountbalances.balance < 0

      

0


source


As shown here :



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

      

+2


source







All Articles