tags:

views:

28

answers:

1

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

+1  A: 

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)

Diego Mijelshon
Thanks! I'm was almost going to start bounty for this question)
kilonet
Too bad I didn't wait, then ;-)
Diego Mijelshon