开发者

NHibernate: help to construct query

My domain:

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

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

I need to query products which Incomes ha开发者_如何学Cve sum of Quantity > 0. I was able to do this with query:

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

However, I need possibility to filter and sort query results by Product properties - that's where I got problems - always getting errors like column "p1_.id" must appear in the GROUP BY clause or be used in an aggregate function


Projections.GroupProperty("Product") only groups on the Product id.

You'll need to group on any other Product properties that you need to use.

(I know, it's not 100% intuitive)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜