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)
精彩评论