按月份和年份零部件集团使用queryover [英] group by month and year parts using queryover

查看:165
本文介绍了按月份和年份零部件集团使用queryover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,它包含一个DateTime字段和价格字段。
我想,让我月/年的聚合列表 - 售价
这样的数据:




  1. 15/01/2012 200

  2. 16/01/2012 200

  3. 15/02/2012 300

  4. 16/02/2012 300

  5. 15/03/2012 400

  6. 16/03/2012 400



我将获得:




  1. 01/2012 400

  2. 02/2012 600

  3. 03/2012 800



所以,到目前为止,我没有找到一个办法才达到这一点使用QueryOver。
我不断收到无法解析财产当我尝试看看日期的月/年部分



这些问题:



组帖子年,然后通过一个月



集团/按日期年/月,部分与NHibernate选择(投影?转型?)



使用LINQ得到了回答 - 不是我要找的。

任何想法?
谢谢



(使用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:

  1. 15/01/2012 200
  2. 16/01/2012 200
  3. 15/02/2012 300
  4. 16/02/2012 300
  5. 15/03/2012 400
  6. 16/03/2012 400

I will get:

  1. 01/2012 400
  2. 02/2012 600
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆