I have a model, that contains a DateTime field and a Price field. I want to get a list that gives me an aggregation of month/year - price so for the data:
I will get:
So far I didn't find a way to achive this using QueryOver. I keep getting "could not resolve property" when i try to look at the Month/Year parts of the date.
Those questions:
Group posts by year, then by month
Group/Sort by Date Year/Month, Partial Select with NHibernate (Projection? Transformation?)
got answered using LINQ - not what I'm looking for.
Any ideas? Thanks
(using NHibernate 3.2)
QueryOver is not a good choice because grouping will need to be done using a SQL expression. For this type of query, QueryOver is simply a pointless abstraction that adds no value.
If you must do it using QueryOver you could do something like:
session.QueryOver<...>()
.SelectList(list => list
.Select(GroupProperty(Projections.SqlProjection(...)))
.SelectSum(x => x.Price)
);