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

When using a cast on OrderBy on SubQuery an Exception is thrown

Description

If you use an casted OrderBy in a SubQuery the following exception is thrown:

Exception thrown: 'System.InvalidOperationException' in System.Core.dll
Additional information:
Rewriting child expression from type
'System.Linq.IOrderedEnumerable`1[ChildObjectType]'
to type
'System.Collections.Generic.KeyValuePair`2[ChildObjectType,System.DateTime]'
is not allowed, because it would change the meaning of the operation.
If this is intentional, override 'VisitUnary' and change it to allow this rewrite.

This Exception is thrown by SqlPreparationExpressionVisitor.Visit.
The problem seems to be that in SqlPreparationSubStatementTableFactory.GetNewSelectExpressionWithOrderings TupleExpressionBuilder.AggregateExpressionsIntoTuple is called which changes the type of the SubQuery to KeyValuePair if the there is an cast on the OrderBy. Without the cast the query works just fine.

It is reproduceable with the following query:

Assignee

Michael Ketting

Reporter

Mario Donhauser

Labels

None

Components

Fix versions

Affects versions

Priority

Normal
Configure