按月份和年份零部件集团使用queryover [英] group by month and year parts using queryover
问题描述
我有一个模型,它包含一个DateTime字段和价格字段。
我想,让我月/年的聚合列表 - 售价
这样的数据:
- 15/01/2012 200
- 16/01/2012 200
- 15/02/2012 300
- 16/02/2012 300
- 15/03/2012 400
- 16/03/2012 400
我将获得:
- 01/2012 400
- 02/2012 600
- 03/2012 800
所以,到目前为止,我没有找到一个办法才达到这一点使用QueryOver。
我不断收到无法解析财产当我尝试看看日期的月/年部分
这些问题:
的集团/按日期年/月,部分与NHibernate选择(投影?转型?)
使用LINQ得到了回答 - 不是我要找的。 p>
任何想法?
谢谢
(使用NHibernate 3.2)
QueryOver是不是一个好的选择,因为分组将需要使用SQL表达式来完成。对于这种类型的查询,QueryOver简直是一个毫无意义的抽象,没有任何价值。
如果你必须使用QueryOver做到这一点,你可以这样做:
session.QueryOver< ...>()
.SelectList(名单=>清单
。选择(GroupProperty (Projections.SqlProjection(...)))
.SelectSum(X => x.Price)
);
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:
- 15/01/2012 200
- 16/01/2012 200
- 15/02/2012 300
- 16/02/2012 300
- 15/03/2012 400
- 16/03/2012 400
I will get:
- 01/2012 400
- 02/2012 600
- 03/2012 800
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)
);
这篇关于按月份和年份零部件集团使用queryover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!