2010-09-10 29 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