Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: compilation error for correlated subquery - order by Length followed by projection of collection navigation #12598

Closed
maumar opened this issue Jul 6, 2018 · 0 comments · Fixed by #17766
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-3.0 type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Jul 6, 2018

Query:

ctx.Customers
.OrderBy(c => c.CustomerID.Length)
.ThenBy(c => c.CustomerID.Length)
.ThenBy(c => c.CustomerID)
.Select(e => e.Orders);

exception:

Unable to cast object of type 'System.Linq.Expressions.PropertyExpression' to type 'Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression'.
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CorrelatedCollectionOptimizingVisitor.<>c__DisplayClass24_0.<CreateJoinToParentQuery>b__1(Expression e)
	at System.Collections.Generic.List`1.FindIndex(Int32 startIndex, Int32 count, Predicate`1 match)
	at System.Collections.Generic.List`1.FindIndex(Predicate`1 match)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CorrelatedCollectionOptimizingVisitor.CreateJoinToParentQuery(QueryModel parentQueryModel, QuerySourceReferenceExpression parentQuerySourceReferenceExpression, Expression outerTargetExpression, IForeignKey foreignKey, QueryModel targetQueryModel, List`1 subQueryProjection)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CorrelatedCollectionOptimizingVisitor.Rewrite(Int32 correlatedCollectionIndex, QueryModel collectionQueryModel, INavigation navigation, Boolean trackingQuery, QuerySourceReferenceExpression originQuerySource, Boolean forceListResult, Type listResultElementType)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CorrelatedCollectionOptimizingVisitor.TryRewrite(SubQueryExpression subQueryExpression, Boolean forceToListResult, Type listResultElementType, Expression& result)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.CorrelatedCollectionOptimizingVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
	at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.TryOptimizeCorrelatedCollections(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
	at Remotion.Linq.Clauses.SelectClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel)
	at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0`1.<Execute>b__0()
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
	at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
	at Remotion.Linq.QueryableBase`1.System.Collections.IEnumerable.GetEnumerator()
	at Microsoft.EntityFrameworkCore.TestUtilities.ProcedurallyGeneratedQueryExecutor.Execute[TElement](IQueryable`1 query)
	at Microsoft.EntityFrameworkCore.TestUtilities.QueryAsserter`1.<AssertQuery>d__11`1.MoveNext()
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
	at Microsoft.EntityFrameworkCore.Query.SimpleQuerySqlServerTest.<Order_by_length_twice>d__384.MoveNext()
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
@maumar maumar changed the title Query: compilation error for correlated subquery with order by Length followed by projection of collection navigation Query: compilation error for correlated subquery - order by Length followed by projection of collection navigation Jul 6, 2018
@divega divega added this to the 2.2.0 milestone Jul 11, 2018
@ajcvickers ajcvickers modified the milestones: 2.2.0, 3.0.0 Aug 3, 2018
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 11, 2019
@smitpatel smitpatel modified the milestones: Backlog, 3.0.0 Sep 11, 2019
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240
Resolves #17243


Close #12889
Close #17243
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240


Close #12889
Close #17243
smitpatel added a commit that referenced this issue Sep 11, 2019
Covers EFCore.Specs.Tests Query folder

Resolves #8366
Resolves #8582
Resolves #8722
Resolves #9007
Resolves #9254
Resolves #12574
Resolves #12579
Resolves #12598
Resolves #12786
Resolves #12787
Resolves #12794
Resolves #12806
Resolves #12827
Resolves #12873
Resolves #14900
Resolves #15862
Resolves #16157
Resolves #17240


Close #12889
Close #17243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-3.0 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants