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 (invalid query model) for query with join on composite key with order by inner sequence and include collection navigation #12802

Closed
maumar opened this issue Jul 25, 2018 · 1 comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed.

Comments

@maumar
Copy link
Contributor

maumar commented Jul 25, 2018

query:

                var query = ctx.Tags.Join(
                    ctx.Gears.OrderBy(gg => gg.FullName),
                    t => new
                    {
                        SquadId = t.GearSquadId,
                        Nickname = t.GearNickName
                    },
                    g => new
                    {
                        SquadId = (int?)g.SquadId,
                        g.Nickname
                    },
                    (t, g) => g).Include(g => g.Weapons);

                var result = query.ToList();

query model (at the point of error):

from CogTag t{0} in DbSet<CogTag>
join Gear g{1} in 
    from Gear gg{2} in DbSet<Gear>
    order by [gg{2}].FullName asc
    select [gg{2}]
on new { 
    [t{0}].GearSquadId, 
    [t{0}].GearNickName
 } equals new { 
    (Nullable<int>)[g{1}].SquadId, 
    [g{1}].Nickname
 }
order by EF.Property(?[g{1}]?, "FullName") asc
select Gear _Include(
    queryContext: queryContext, 
    entity: [g{1}], 
    included: new object[]{ }, 
    fixup: (QueryContext queryContext | Gear entity | object[] included) => 
    {
        return void queryContext.QueryBuffer.IncludeCollection(
            includeId: 0, 
            navigation: Gear.Weapons, 
            inverseNavigation: Weapon.Owner, 
            targetEntityType: EntityType: Weapon, 
            clrCollectionAccessor: ClrICollectionAccessor<Gear, ICollection<Weapon>, Weapon>, 
            inverseClrPropertySetter: ClrPropertySetter<Weapon, Gear>, 
            tracking: False, 
            instance: entity, 
            valuesFactory: () => 
                from Weapon g.Weapons{3} in DbSet<Weapon>
                join AnonymousObject _g{4} in 
                    (from CogTag t{5} in DbSet<CogTag>
                    join Gear g{6} in 
                        from Gear gg{7} in DbSet<Gear>
                        order by [gg{7}].FullName asc
                        select [gg{7}]
                    on new { 
                        [t{5}].GearSquadId, 
                        [t{5}].GearNickName
                     } equals new { 
                        (Nullable<int>)[g{6}].SquadId, 
                        [g{6}].Nickname
                     }
                    select new AnonymousObject(new object[]{ (object)EF.Property(?[g{6}]?, "FullName") })).Distinct()
                on Property([g.Weapons{3}], "OwnerFullName") equals (string)object [_g{4}].GetValue(0)
                order by object [_g{4}].GetValue(0) asc
                select [g.Weapons{3}], 
            joinPredicate: (Gear p | Weapon d) => d.OwnerFullName == default(string) ? False : p.FullName == d.OwnerFullName)
    })

exception:

The property '' on entity type 'Gear' could not be found. Ensure that the property exists and has been included in the model.
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MemberAccessBindingExpressionVisitor.GetPropertyPath(Expression expression, QueryCompilationContext queryCompilationContext, QuerySourceReferenceExpression& querySourceReferenceExpression)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.BindPropertyExpressionCore[TResult](Expression propertyExpression, IQuerySource querySource, Func`3 propertyBinder)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.BindMethodCallExpression[TResult](MethodCallExpression methodCallExpression, IQuerySource querySource, Func`3 methodCallBinder)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.BindMethodCallExpression[TResult](MethodCallExpression methodCallExpression, IQuerySource querySource, Func`4 memberBinder, Boolean bindSubQueries)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.BindMethodCallExpression[TResult](MethodCallExpression methodCallExpression, Func`4 memberBinder, Boolean bindSubQueries)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.DefaultQueryExpressionVisitor.VisitExtension(Expression node)
	at System.Linq.Expressions.Expression.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 System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
	at System.Linq.Expressions.ExpressionVisitor.VisitNewArray(NewArrayExpression node)
	at System.Linq.Expressions.NewArrayExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](ReadOnlyCollection`1 nodes, String callerName)
	at Remotion.Linq.Parsing.RelinqExpressionVisitor.VisitNew(NewExpression expression)
	at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
	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.RelationalQueryModelVisitor.VisitSubQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.LiftSubQuery(IQuerySource querySource, SubQueryExpression subQueryExpression)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileJoinClauseInnerSequenceExpression(JoinClause joinClause, QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.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.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
	at Remotion.Linq.Clauses.Expressions.SubQueryExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
	at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
	at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
	at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
	at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
	at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
	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.GetEnumerator()
	at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable`2.GetEnumerator()
	at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
@ajcvickers
Copy link
Member

Closing this as it uses the same kind of Include pattern as discussed in #12181, with a note added to #12737 where we are tracking possible Include semantics going forward.

@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Jul 30, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed.
Projects
None yet
Development

No branches or pull requests

2 participants