3
我需要查詢計數基於每一天以及組由相同的標準。生成的查詢應該類似於NHibernate的選擇與SqlFunction列,按照相同的標準組
select SendTo, dateadd(dd,
0,
datediff(dd,
0,
WorkToBeginDate))
from Locates
group by SendTo, dateadd(dd,
0,
datediff(dd,
0,
WorkToBeginDate))
我目前使用下面的查詢,但它由date
不羣。
var dateGroupBy = Projections.SqlFunction("date", NHibernateUtil.Date,
Projections.Group<Domain.Locate>(g => g.WorkToBeginDate));
var stats =
_session.QueryOver<Domain.Locate>()
.SelectList(x => x
.SelectGroup(xx => xx.SendTo).WithAlias(() => statsDto.SentTo)
.SelectCount(xx => xx.LocateId).WithAlias(() => statsDto.Count)
.Select(dateGroupBy)
.WithAlias(() => statsDto.DueDate))
.TransformUsing(Transformers.AliasToBean<StatsDto>())
.List<StatsDto>();
執行此查詢產生
SELECT this_.SendTo as y0_,
count(this_.LocateId) as y1_,
dateadd(dd,
0,
datediff(dd,
0,
this_.WorkToBeginDate)) as y2_
FROM Locates this_
GROUP BY this_.SendTo,
this_.WorkToBeginDate
我猜想這是因爲我使用Select
和我的預測並不SelectGroup
。我試過.SelectGroup(xx => new SqlFunctionProjection("date", NHibernateUtil.Date, Projections.Group<Domain.Locate>(g => g.WorkToBeginDate)))
,但是這給了我Could not determine member from new SqlFunctionProjection("date", NHibernateUtil.Date, new [] {Group(g => Convert(g.WorkToBeginDate))})
。
我打電話給這個shenanigans! – ChickSentMeHighE 2011-05-17 01:04:55