How to add groupby in query over nhibernate?
Asked Answered
C

2

5

How can I add groupby Id to this nhibernate code because I'm new with it and there is many way but none work for me.

.Select(Projections.Sum(() => ServiceOrderItem.WorkTime), 
    Projections.ProjectionList().Add(Projections.Property(
        () => ServiceOrder.Id).WithAlias(() => TechnicianWorkTime.Id))
    )

There will be more in ProjectionList...

Console answered 15/5, 2012 at 14:8 Comment(1)
Very difficult to answer without whole query, class definitions and expected result. Maybe this could help you https://mcmap.net/q/1923437/-nhibernate-aggregate-query-for-one-to-many-relationRadiotelegram
M
13

You can use SelectList for it:

query.SelectList(list => list
  .SelectGroup(() => ServiceOrder.Id)
  .SelectSum(() => ServiceOrderItem.WorkTime));
Martijn answered 15/5, 2012 at 15:57 Comment(0)
C
0

You can do this as well:

objQuery = objQuery.SelectList(list => list.SelectGroup((x => x.Id)));
Coats answered 28/9, 2016 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.