Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有子集合属性的对象的NHibernate查询_Nhibernate_Hql_Criteria - Fatal编程技术网

具有子集合属性的对象的NHibernate查询

具有子集合属性的对象的NHibernate查询,nhibernate,hql,criteria,Nhibernate,Hql,Criteria,我需要nhibernate查询的帮助。如果可能的话,我更愿意使用CriteriaAPI,否则HQL是可以的 我有一个带有Account对象属性的Employee对象,Account有一个Entry对象集合,每个Entry都有一个Amount属性 我需要一个查询,该查询将返回所有拥有一个帐户的员工,该帐户的分录金额之和小于零 有什么想法吗?如果有帮助的话。。。使用命名查询解决了此问题。不确定是否可以使用标准API 查询: select employee.* from employee join (

我需要nhibernate查询的帮助。如果可能的话,我更愿意使用CriteriaAPI,否则HQL是可以的

我有一个带有Account对象属性的Employee对象,Account有一个Entry对象集合,每个Entry都有一个Amount属性

我需要一个查询,该查询将返回所有拥有一个帐户的员工,该帐户的分录金额之和小于零


有什么想法吗?

如果有帮助的话。。。使用命名查询解决了此问题。不确定是否可以使用标准API

查询:

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
如图所示:


仅使用NHibernate可能并不容易。我混合使用NH+Linq,让员工使用NH账户和Linq计算。这是我的方法,可能不是最好的,但对我来说没关系:
ICriteria.CreateCriteria(typeof(Customer))
.Add(Expression.Eq("Firstname", "Steve"))
.CreateCriteria("Orders")
.Add(Expression.Gt("OrderDate", new  Datetime.Now)))
.List<Customer>();