Skip to content

Query: NRE for query with top level DefaultIfEmpty and projecting a constant #12567

Closed

Description

@maumar

query using Northwind model:

from e in ctx.Employees.Where(c => c.EmployeeID == NonExistentID).DefaultIfEmpty()
select "Foo";

query plan:

(QueryContext queryContext) => IEnumerable<string> _InterceptExceptions(
|__ source: IEnumerable<string> DefaultIfEmpty(IEnumerable<string> _DefaultIfEmptyShapedQuery(
|   |__ queryContext: queryContext, 
|   |__ shaperCommandContext: SelectExpression: 
|   |       SELECT 1
|   |       FROM (
|   |           SELECT NULL AS [empty]
|   |       ) AS [empty]
|   |       LEFT JOIN (
|   |           SELECT [c].*
|   |           FROM [Employees] AS [c]
|   |           WHERE [c].[EmployeeID] = -1
|   |       ) AS [t] ON 1 = 1, 
|   |__ shaper: (QueryContext queryContext | ValueBuffer c) => "Foo")), 
|__ contextType: TestModels.Northwind.NorthwindRelationalContext, 
|__ logger: DiagnosticsLogger<Query>, 
|__ queryContext: Unhandled parameter: queryContext)

Exception:

System.NullReferenceException : Object reference not set to an instance of an object.
	at Microsoft.EntityFrameworkCore.Storage.ValueBuffer.get_Count()
	at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_DefaultIfEmptyShapedQuery>d__11`1.MoveNext()
	at System.Linq.Enumerable.<DefaultIfEmptyIterator>d__93`1.MoveNext()
	at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
	at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
	at Microsoft.EntityFrameworkCore.Query.SimpleQueryTestBase`1.Default_if_empty_top_level(Boolean isAsync)
	at Microsoft.EntityFrameworkCore.Query.SimpleQuerySqlServerTest.<>n__7(Boolean isAsync)
	at Microsoft.EntityFrameworkCore.Query.SimpleQuerySqlServerTest.<Default_if_empty_top_level>d__14.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)

Activity

  1. modified the milestones: Backlog, 3.0.0 on Jul 6, 2018
  2. smitpatel commented on Nov 16, 2018

    @smitpatel
    Contributor

    ValueBuffer did not have any values! 🤦‍♂️

  3. modified the milestones: 3.0.0, Backlog on Jun 20, 2019
  4. removed their assignment
    on Jun 24, 2019
  5. 2 remaining items

  6. self-assigned this
    on Aug 10, 2019
  7. modified the milestones: Backlog, 3.0.0 on Aug 10, 2019
  8. added 3 commits that reference this issue on Aug 10, 2019
    d90e9ce
    09f58e2
    8273469
  9. added a commit that references this issue on Aug 13, 2019
    d11f607
  10. modified the milestones: 3.0.0, on Aug 21, 2019
  11. modified the milestones: , 3.0.0 on Nov 11, 2019
  12. 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