Month and year group using query

I have a model containing a DateTime field and a Price field. I want to get a list that gives me the aggregation of the month / year - the price is therefore for the data:

  • 01/15/2012 200
  • 01/16/2012 200
  • 02/15/2012 300
  • 02/16/2012 300
  • 03/15/2012 400
  • 03/16/2012 400

I will get:

  • 01/2012 400
  • 02/2012 600
  • 03/2012 800

So far, I have not found a way to achieve this with QueryOver. I keep getting “cannot resolve property” when I try to see parts of the month / year of the date.

These questions:

Grouping by year, then by month

Group / Sort by date Year / Month, Partial selection using NHibernate (Projection Transformation?)

got the answer using LINQ - not what I'm looking for.

Any ideas? Thanks

(using NHibernate 3.2)

+2
1

QueryOver , SQL. QueryOver , .

QueryOver, - :

session.QueryOver<...>()
   .SelectList(list => list
      .Select(GroupProperty(Projections.SqlProjection(...)))
      .SelectSum(x => x.Price)
   );
+2

All Articles