Nhibernate按倍数和计数分组

Nhibernate按倍数和计数分组,nhibernate,count,group-by,hql,linq-to-nhibernate,Nhibernate,Count,Group By,Hql,Linq To Nhibernate,首先,我知道GroubBy的多个属性尚未实现 我想做的是 SELECT count(*) FROM ( SELECT this_.SubmissionDate as y0_ FROM [Coupon] this_ WHERE this_.PaymentOrder_id is null GROUP BY this_.SubmissionDate, this_.Deal_id ) AS query 我在Nhibernate最好的是 S

首先,我知道GroubBy的多个属性尚未实现

我想做的是

SELECT count(*)
FROM ( 
    SELECT this_.SubmissionDate as y0_
    FROM   [Coupon] this_
    WHERE  this_.PaymentOrder_id is null 
    GROUP BY this_.SubmissionDate,
           this_.Deal_id
) AS query
我在Nhibernate最好的是

Session.QueryOver<Coupon>().Select(Projections.Group<Coupon>(e => e.SubmissionDate),Projections.Group<Coupon>(e => e.Deal.Id)).Future<object[]>().Count()
更多例外

[QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21]
   NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() +118
   NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() +416

你有没有试过这样的方法,可以在记忆中计数

var count = Session.CreateQuery("select c.SubmissionDate from Coupon c where c.PaymentOrder.Id is null group by c.SubmissionDate, c.Deal.Id").ToList().Count;
HQL似乎不支持select和where之外的子查询:


否则,您可以创建一个存储过程,并将其添加到映射中:

运行它时会发生什么?Antlr异常似乎是由于HQL语法不正确造成的。请参阅:。异常是否像上面的链接中那样由QuerySyntaxException包装?我很确定是子选择导致的!但我不知道这会不会返回整个结果集并在内存中计算它们?
[QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21]
   NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() +118
   NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() +416
var count = Session.CreateQuery("select c.SubmissionDate from Coupon c where c.PaymentOrder.Id is null group by c.SubmissionDate, c.Deal.Id").ToList().Count;