首先我知道GroubBy多個屬性尚未實現。Nhibernate GroupBy倍數和計數
我想要做的是
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()
帶來整套,然後數了。
我發現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>();
不工作。拋出一個
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
會發生什麼它? – 2011-05-26 13:26:35
編輯添加異常 – 2011-05-26 13:32:08
Antlr異常似乎是由於不正確的HQL語法。 請參閱:http://stackoverflow.com/questions/3799087/nhibernate-antlr-runtime-noviablealtexception。 像上面的鏈接一樣,QuerySyntaxException是否包含異常? – Tomas 2011-05-26 14:07:34