We're updating the issue view to help you get more done. 

Conditional expressions in LINQ Select

Description

Seems, that after was fixed there is some regression with conditional expressions in select statements:

Works:

1 2 3 4 5 6 7 8 9 10 var catInfo = session.Query<MyLovelyCat>() .Select(o => new { o.Color, AliveDays = (int)(DateTime.Now - o.Birthdate).TotalDays, o.Name, o.Price, }) .Single();

Does not works:

1 2 3 4 5 6 7 8 9 10 var catInfo2 = session.Query<MyLovelyCat>() .Select(o => new { o.Color, AliveDays = o.Price > 0 ? (DateTime.Now - o.Birthdate).TotalDays : 0, o.Name, o.Price, }) .Single();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 NHibernate.Test.SqlLogSpy NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : A recognition error occurred. [.Single[<>f__AnonymousType127`4[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]](.Select[NHibernate.Test.NHSpecificTest.NHxxxx.MyLovelyCat,<>f__AnonymousType127`4[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]](NHibernate.Linq.NhQueryable`1[NHibernate.Test.NHSpecificTest.NHxxxx.MyLovelyCat], Quote((o, ) => (new <>f__AnonymousType127`4(o.Color, Decimal.op_GreaterThan(o.Price, 0) ? DateTime.op_Subtraction(18.08.2015 13:46:24, o.Birthdate).TotalDays : 0, o.Name, o.Price, ))), ), )] в NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() в ErrorCounter.cs: line 73 в NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() в QueryTranslatorImpl.cs: line 574 в NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole) в QueryTranslatorImpl.cs: line 423 в NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole) в QueryTranslatorImpl.cs: line 361 в NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) в ASTQueryTranslatorFactory.cs: line 39 в NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) в QueryPlanCache.cs: line 67 в NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) в AbstractSessionImpl.cs: line 412 в NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) в AbstractSessionImpl.cs: line 372 в NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) в DefaultQueryProvider.cs: line 73 в NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) в DefaultQueryProvider.cs: line 39 в NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) в DefaultQueryProvider.cs: line 46 в NHibernate.Test.NHSpecificTest.NHxxxx.Fixture.SelectConditionalValuesTest() в Fixture.cs: line 52 13:46:24,296 ERROR Parser:379 - NoViableAltException(80@[]) 13:46:24,362 ERROR Parser:379 - NoViableAltException(80@[]) 13:46:24,410 ERROR Parser:379 - MismatchedTreeNodeException(23!=3) 13:46:24,469 ERROR Parser:379 - MismatchedTreeNodeException(23!=3)

Attaching failing test

Environment

None

Status

Assignee

Alexander Zaytsev

Reporter

Anton Nemo

Components

Fix versions

Affects versions

4.1.0

Priority

Critical