Nhibernate 3 Linq引发Antlr.Runtime.NoViableAltException [英] Nhibernate 3 Linq throws Antlr.Runtime.NoViableAltException

查看:192
本文介绍了Nhibernate 3 Linq引发Antlr.Runtime.NoViableAltException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NHibernate 3 linq提供程序,我想选择子项的最大数量.

Using the NHibernate 3 linq provider I would like to select the max count of an items children.

使用以下linq查询,我得到一个Antlr.Runtime.NoViableAltException,然后是一个Antlr.Runtime.MismatchedTreeNodeException

Using the following linq query I get an Antlr.Runtime.NoViableAltException followed by an Antlr.Runtime.MismatchedTreeNodeException

int maxCount = _repository.FindAll<Device>().Max(d=>d.DeviceSensors.Count());

存储库函数FindAll()返回session.Query.

The repository function FindAll() returns session.Query.

异常详细信息:

Antlr.Runtime.NoViableAltException occurred
  Message="Exception of type 'Antlr.Runtime.NoViableAltException' was thrown."
  Source="NHibernate"
  Char=0
  CharPositionInLine=-1
  Index=21
  Line=0
  UnexpectedType=84
  StackTrace:
       at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.aggregateExpr() in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Generated\HqlSqlWalker.cs:line 3203
  InnerException: 

.

Antlr.Runtime.MismatchedTreeNodeException occurred
  Message="Exception of type 'Antlr.Runtime.MismatchedTreeNodeException' was thrown."
  Source="Antlr3.Runtime"
  Char=0
  CharPositionInLine=-1
  Index=21
  Line=0
  UnexpectedType=84
  StackTrace:
       at Antlr.Runtime.Tree.TreeParser.RecoverFromMismatchedToken(IIntStream input, Int32 ttype, BitSet follow)
       at Antlr.Runtime.BaseRecognizer.Match(IIntStream input, Int32 ttype, BitSet follow)
       at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.functionCall() in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Generated\HqlSqlWalker.cs:line 7906
  InnerException:


 NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.First(.Select(.OrderByDescending(NHibernate.Linq.NhQueryable`1[RGB.TTT.Domain.Device], Quote((x, ) => (x.DeviceSensors.Count)), ), Quote((x, ) => (new <>f__AnonymousType2`1(x.DeviceSensors.Count, ))), ), )]

这是一个已知问题吗?还是我必须重写查询,欢迎提出任何建议.

Is this a known problem? Or do I have to rewrite the query, any suggestions are more then welcome.

推荐答案

显然,当前的NHibernate Linq提供程序无法在Select子句中组合Max()和内部Select.您可能需要将"Max"从查询"中拉出,然后再应用它,例如

Apparently the current NHibernate Linq provider cannot combine Max() and an inner Select in the Select clause. You may need to pull the Max out of the Query and apply it afterwards, e.g.

int maxCount = session.Query<Device>()
    .Select(d => d.DeviceSensors.Count)
    .ToList()
    .Max();

没有子选择的更简单版本可以工作:

A simpler version without a sub select works:

int maxCount = session.Query<Device>()
    .Select(d => d.Name.Length)
    .Max();

这篇关于Nhibernate 3 Linq引发Antlr.Runtime.NoViableAltException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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