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 queries with join where the inner key is navigation #11245

Closed
maumar opened this issue Mar 13, 2018 · 2 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Mar 13, 2018

repro using GearsOfWar model

from g1 in ctx.Gears
join g2 in ctx.Gears on g1.AssignedCity equals g2.AssignedCity
select new { Nickname1 = g1.Nickname, Nickname2 = g2.Nickname };

throws:

Property 'Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.City AssignedCity' is not defined for type 'Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.City'
	at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
	at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
	at Microsoft.EntityFrameworkCore.Internal.ExpressionExtensions.MakeMemberAccess(Expression expression, MemberInfo member)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.<>c__DisplayClass19_0.<VisitMember>b__1(Expression e)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.CreateSubqueryForNavigations(Expression outerQuerySourceReferenceExpression, ICollection`1 navigations, Func`2 propertyCreator)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.RewriteNavigationProperties(IReadOnlyList`1 properties, IQuerySource querySource, Expression expression, Expression declaringExpression, String propertyName, Type propertyType, Func`2 propertyCreator, Func`2 conditionalAccessPropertyCreator)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.<>c__DisplayClass19_0.<VisitMember>b__0(IReadOnlyList`1 ps, IQuerySource qs)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.BindPropertyExpressionCore[TResult](Expression propertyExpression, IQuerySource querySource, Func`3 propertyBinder)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.BindNavigationPathPropertyExpression[TResult](Expression propertyExpression, Func`3 propertyBinder)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.VisitMember(MemberExpression node)
	at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.NavigationRewritingQueryModelVisitor.VisitJoinClauseInternal(JoinClause joinClause)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.NavigationRewritingQueryModelVisitor.VisitJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index)
	at Remotion.Linq.Clauses.JoinClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
	at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
	at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.NavigationRewritingExpressionVisitor.Rewrite(QueryModel queryModel, QueryModel parentQueryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
	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.GetEnumerator()
@maumar
Copy link
Contributor Author

maumar commented Mar 13, 2018

problem is that inner key nav rewrite goes thru a different code path (needs to be converted to subquery rather than join, because chicken-and-egg problem), and we have some invalid assumptions when the key doesn't have a scalar member at the end

@ajcvickers ajcvickers added this to the 2.1.0 milestone Mar 14, 2018
maumar added a commit that referenced this issue Mar 15, 2018
#11022 - GroupJoin with an entity object as a key fails
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark qsre projected out of subquery that is a result of nav rewrite of join/groupjoin inner key.
maumar added a commit that referenced this issue Mar 15, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark qsre projected out of subquery that is a result of nav rewrite of join/groupjoin inner key.
maumar added a commit that referenced this issue Mar 15, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation
#9481 - EF Core joining on the wrong field when using GroupBy

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark qsre projected out of subquery that is a result of nav rewrite of join/groupjoin inner key.
maumar added a commit that referenced this issue Mar 16, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation
#11022 - Query: GroupJoin with a complex join key fails during compilation
#9481 - EF Core joining on the wrong field when using GroupBy

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark for materialization query sources coming from subquery join keys.
maumar added a commit that referenced this issue Mar 19, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation
#11022 - Query: GroupJoin with a complex join key fails during compilation
#9481 - EF Core joining on the wrong field when using GroupBy

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark for materialization query sources coming from subquery join keys.
maumar added a commit that referenced this issue Mar 20, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation
#11022 - Query: GroupJoin with a complex join key fails during compilation
#9481 - EF Core joining on the wrong field when using GroupBy

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark for materialization query sources coming from subquery join keys.
maumar added a commit that referenced this issue Mar 20, 2018
#11288 - Query: Join/GroupJoin where key selectors are qsres or navigations fails during compilation
#10974 - Query: Include Collection group by reference throws exception
#11245 - Query: compilation error for queries with join where the inner key is navigation
#11022 - Query: GroupJoin with a complex join key fails during compilation
#9481 - EF Core joining on the wrong field when using GroupBy

- Added step to the QueryOptimizer that converts entity qsre comparison to key comparisons instead for order by join and group join,
- Improved logic of join/groupjoin inner key navigation rewrite to correctly handle case when navigation is the final operator (i.e. no scalar is projected at the end),
- Improved "requires materialization" logic to correctly mark for materialization query sources coming from subquery join keys.
@maumar
Copy link
Contributor Author

maumar commented Mar 20, 2018

fixed in fdb8ece

@maumar maumar closed this as completed Mar 20, 2018
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Mar 20, 2018
@ajcvickers ajcvickers modified the milestones: 2.1.0-preview2, 2.1.0 Nov 11, 2019
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. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants