Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

Fixes #37337

Description

EF doesn't currently support shadow properties on complex types. However, the discriminator property is special-cased (it's used internally by EF to distinguish null vs empty complex properties). Unfortunately, there was a code path missed.

Customer impact

Applications that use a discriminator on a nullable complex property will fail at runtime when querying the affected entities. There is no good workaround for this.

How found

Customer reported on EF 10.0.0, this is a relatively common scenario for optional complex properties.

Regression

No, new feature in EF 10.

Testing

Test added.

Risk

Low. The fix is targeted and quirked.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix ArgumentOutOfRangeException for entity with shadow property Dec 18, 2025
Copilot AI requested a review from AndriySvyryd December 18, 2025 00:21
@AndriySvyryd
Copy link
Member

@copilot Update progress by rewriting the PR summary using this template:

Fixes #{number}

**Description**
{Issue description}

**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}

**How found**
{Was it customer reported or found during verification? How many customers are affected?}

**Regression**
{Is it a regression from a released version? Which one?}

**Testing**
{How the changes were tested}

**Risk**
{Low/Medium/High, argument why}
Copy link
Contributor Author

Copilot AI commented Dec 19, 2025

@copilot Update progress by rewriting the PR summary using this template:

...

Updated the PR description using the requested template format.

@AndriySvyryd AndriySvyryd changed the title Fix ArgumentOutOfRangeException for entities with shadow properties and nullable complex types with discriminators Dec 19, 2025
@AndriySvyryd AndriySvyryd marked this pull request as ready for review December 19, 2025 07:34
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner December 19, 2025 07:34
Copilot AI review requested due to automatic review settings December 19, 2025 07:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an ArgumentOutOfRangeException that occurs when querying entities that have both shadow properties and nullable complex types with discriminators (issue #37337). The fix ensures that shadow properties on complex types are replaced with default values during snapshot creation, since shadow property materialization on complex types is not currently supported in EF Core.

Key Changes:

  • Added an AppContext switch Microsoft.EntityFrameworkCore.Issue37337 for backward compatibility control
  • Modified SnapshotFactoryFactory.CreateSnapshotExpression to handle shadow properties on complex types by using default values instead of attempting materialization
  • Added comprehensive test coverage to verify the fix works correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs Implements the fix by detecting shadow properties on complex types and substituting them with default values during snapshot creation, controlled by an AppContext switch
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs Adds a test that reproduces the scenario with shadow properties, nullable complex types with discriminators, and verifies the fix works correctly
…ies on complex types in snapshot creation

Fixes #37337

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-argument-out-of-range-exception branch from a6d621a to 9501372 Compare December 19, 2025 20:52
@AndriySvyryd AndriySvyryd marked this pull request as ready for review December 19, 2025 21:18
Copilot AI review requested due to automatic review settings December 19, 2025 21:18
@AndriySvyryd AndriySvyryd requested a review from a team December 19, 2025 21:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants