2011-04-13 5 views
1

NHibernate 3 linq 공급자를 사용하여 항목의 최대 개수를 선택하고 싶습니다.Nhibernate 3 Linq가 Antlr.Runtime.NoViableAltException을 던졌습니다

내가 Antlr.Runtime.MismatchedTreeNodeException

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

저장소 기능 findall은() 뒤에 Antlr.Runtime.NoViableAltException을 얻을 다음과 같은 LINQ 쿼리를 사용하면 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,))),),)] 

이 알려진 문제인가? 또는 쿼리를 다시 작성해야합니다. 모든 제안을 환영합니다.

답변

2

분명히 현재 NHibernate Linq 프로 바이더는 Select 절에서 Max()와 내부 Select를 결합 할 수 없다. 쿼리에서 최대 값을 가져와 나중에 적용해야 할 수 있습니다.

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

서브없는 간단한 버전을 선택 작품 :

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