Skip to content

Query: compilation error (Operation is not valid due to the current state of the object) for query with DefaultIfEmpty joined with itself #12872

Closed

Description

@maumar

query:

                var query =
                    (from e in ctx.Employees.Where(c => c.EmployeeID > 0).DefaultIfEmpty()
                     select e).Join(from e in ctx.Employees.Where(c => c.EmployeeID > 0).DefaultIfEmpty()
                                    select e, o => o, i => i, (o, i) => o);

                var result = query.ToList();

exception:

Operation is not valid due to the current state of the object.
	at System.Linq.Expressions.MethodCallExpression1.System.Linq.Expressions.IArgumentProvider.GetArgument(Int32 index)
	at System.Linq.Expressions.ListArgumentProvider.get_Item(Int32 index)
	at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.TryFlattenJoin(JoinClause joinClause, QueryModel queryModel, Int32 index, Int32 previousProjectionCount, ParameterExpression previousParameter, Dictionary`2 previousMapping)
	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.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 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Activity

  1. added this to the 3.0.0 milestone on Aug 3, 2018
  2. modified the milestones: 3.0.0, Backlog on Jun 20, 2019
  3. removed their assignment
    on Jun 24, 2019
  4. self-assigned this
    on Aug 10, 2019
  5. modified the milestones: Backlog, 3.0.0 on Aug 10, 2019
  6. added 3 commits that reference this issue on Aug 10, 2019
    d90e9ce
    09f58e2
    8273469
  7. added a commit that references this issue on Aug 13, 2019
    d11f607
  8. modified the milestones: 3.0.0, on Aug 21, 2019
  9. modified the milestones: , 3.0.0 on Nov 11, 2019
  10. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions