Nhibernate GroupBy 多个和计数
首先我知道 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()
带来整个集合,然后对其进行计数。
我找到了这个并创建了
var count = Session.CreateQuery("select count(*) from (select c.SubmissionDate from Coupon c where c.PaymentOrder.Id is null group by c.SubmissionDate, c.Deal.Id) as query").FutureValue<Int32>();
这个不起作用。抛出
Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21
Exception Details: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21
更多异常
[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
First off I know GroubBy multiple properties has not been implemented yet.
What I want to do is
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
the best I have in Nhibernate is
Session.QueryOver<Coupon>().Select(Projections.Group<Coupon>(e => e.SubmissionDate),Projections.Group<Coupon>(e => e.Deal.Id)).Future<object[]>().Count()
which brings the whole set and then counts it.
I have found this and created this
var count = Session.CreateQuery("select count(*) from (select c.SubmissionDate from Coupon c where c.PaymentOrder.Id is null group by c.SubmissionDate, c.Deal.Id) as query").FutureValue<Int32>();
which doesn't work. Throws a
Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21
Exception Details: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 21
more exception
[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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过这样的事情,它将在内存中进行计数?
HQL 似乎不支持 select 和 where 之外的子查询: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-subqueries
否则,您可以创建一个存储过程,并将其添加到您的映射:正确的 NHibernate 映射存储过程?
Did you try something like this, that will do the counting in memory ?
HQL doesn't seem to support subqueries outside select and where : http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-subqueries
Otherwise, you could create a stored procedure, and add it in your mapping : Correct NHibernate Mapping For Stored Procedure?