Queries with sub-query in ThenBy fail

Description

I added two unit tests hereto show the issue.

While 'AscendingOrderBySubqueryClause' runs fine, produces valid SQL and thus shows that the subquery in OrderBy is perfectly legal, 'AscendingOrderByClauseThenBySubquery' fails with the exception shown below.

I investigated this a bit, the HQL-trees for the sub-queries seem to be identical, the bug seems to be in the HQL-SQL-translation. I will try to gain some more insight, however, I can't really wrap my head around the code in HqlSqlWalker.cs.

Exception:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : A recognition error occurred. [.Select[NHibernate.DomainModel.Northwind.Entities.Customer,System.String](.ThenBy[NHibernate.DomainModel.Northwind.Entities.Customer,System.Int32](.OrderBy[NHibernate.DomainModel.Northwind.Entities.Customer,System.String](NHibernate.Linq.NhQueryable`1[NHibernate.DomainModel.Northwind.Entities.Customer], Quote((c, ) => (c.CustomerId)), ), Quote((c, ) => (.Count[NHibernate.DomainModel.Northwind.Entities.Employee](NHibernate.Linq.NhQueryable`1[NHibernate.DomainModel.Northwind.Entities.Employee], ))), ), Quote((c, ) => (c.CustomerId)), )]
bei NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()
bei NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
bei NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole)
bei NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole)
bei NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow)
bei NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
bei NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
bei NHibernate.Engine.Query.QueryExpressionPlan.CreateTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
bei NHibernate.Engine.Query.QueryExpressionPlan..ctor(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
bei NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
bei NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
bei NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
bei NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
bei NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
bei NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
bei Remotion.Linq.QueryableBase`1.GetEnumerator()
bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
bei Hibernate.Test.Linq.ByMethod.OrderByTests.AscendingOrderByClauseThenBySubquery()

11:52:36,914 ERROR Parser:378 - MismatchedTreeNodeException(105!=3)

Environment

.net 4,6, Windows 10

Status

Assignee

Alex Zaytsev

Reporter

Daniel Weber

Labels

Components

Affects versions

4.0.4

Priority

Minor
Configure