2010-09-10 65 views
0

我的域名:NHibernate的:有利于构造查询

class Product 
{ 
    IList<Income> Incomes {get; set;} 
    Category Category {get; set;} 
} 

class Income 
{ 
    Product Product {get; set;} 
    int Quantity {get; set; } 
} 

我需要查询其收入的数量之和产品> 0,我能够与查询做到这一点:

ICriteria criteria = session.CreateCriteria(typeof (Income)) 
       .SetProjection(Projections.GroupProperty("Product")) 
       .Add(Restrictions.Ge(Projections.Sum("Quantity"), 1)); 

然而,我需要根据产品属性筛选和排序查询结果的可能性 - 这就是我遇到问题的地方 - 总是得到像column "p1_.id" must appear in the GROUP BY clause or be used in an aggregate function

回答

2

Projections.GroupProperty("Product")只有组在产品ID上。

您需要对您需要使用的任何其他产品属性进行分组。

(我知道,它不是100%直观的)

+0

谢谢!我几乎要开始赏金这个问题) – kilonet 2010-09-13 18:37:29

+0

太糟糕了,我没有等,然后;-) – 2010-09-13 18:46:17