-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[release/10.0] Fix ArgumentOutOfRangeException for entities with shadow properties and nullable complex types with discriminators #37394
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
base: release/10.0
Are you sure you want to change the base?
Conversation
test/EFCore.InMemory.FunctionalTests/Query/AdHocComplexTypeQueryInMemoryTest.cs
Outdated
Show resolved
Hide resolved
|
@copilot Update progress by rewriting the PR summary using this template: |
... Updated the PR description using the requested template format. |
There was a problem hiding this 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.Issue37337for backward compatibility control - Modified
SnapshotFactoryFactory.CreateSnapshotExpressionto 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 |
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
Outdated
Show resolved
Hide resolved
…ies on complex types in snapshot creation Fixes #37337 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
a6d621a to
9501372
Compare
There was a problem hiding this 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.
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.