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 have 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