[release/10.0] Restore ordinals when transitioning complex collection entries from Deleted state#37729
Conversation
test/EFCore.SqlServer.FunctionalTests/ComplexTypesTrackingSqlServerTest.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
@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}
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Outdated
Show resolved
Hide resolved
src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs
Outdated
Show resolved
Hide resolved
src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #37724 where changing the state of an entity with a complex collection from Deleted to Unchanged throws an InvalidOperationException about invalid ordinal '-1'. The issue prevents customers from implementing soft-delete patterns with entities that have complex collections in EF Core 10.
Changes:
- Restore
OrdinalfromOriginalOrdinalwhen transitioning complex collection entries from Deleted state to prevent validation errors - Include quirk mode switch
UseOldBehavior37724for backwards compatibility - Remove dead code that attempted to insert entries into original collection when transitioning from Deleted to Unchanged (this is now handled by the ordinal restoration)
- Refactor
InsertEntrymethod to make early-return logic more explicit
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore/ChangeTracking/Internal/InternalComplexEntry.cs | Adds quirk mode switch and ordinal restoration logic when transitioning from Deleted state |
| src/EFCore/ChangeTracking/Internal/InternalEntryBase.InternalComplexCollectionEntry.cs | Removes duplicate InsertEntry call and refactors null check logic for clarity |
| test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs | Adds unit test for Deleted→Unchanged state transition with complex collections |
| test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs | Adds comprehensive specification tests covering various complex type scenarios (collections, structs, records, fields) for state transitions from Deleted |
roji
left a comment
There was a problem hiding this comment.
LGTM, but @AndriySvyryd am noticing that only one code path has the quirk.
artl93
left a comment
There was a problem hiding this comment.
Approved. New feature. Customer reported. Workaround seems non-obvious.
Fixes #37724 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
135d82d to
3f8b788
Compare
Fixes #37724
Description
When changing the state of an entity with a complex collection from
DeletedtoUnchanged, anInvalidOperationExceptionis thrown with the message "Complex entry ordinal '-1' is invalid for the collection" because deleted entries have -1 as the ordinal in the collection, since they are no longer part of the collection.Customer impact
This prevents customers from implementing soft-delete patterns with entities that have complex collections.
Workaround: Customers can change the state to
Modifiedinstead ofUnchangedHow found
Customer reported on 10.0.3.
Regression
No. Complex collections are a new feature in EF Core 10.
Testing
Tests added.
Risk
Low. The fix is surgical and minimal. A quirk mode switch is included to revert to old behavior if needed.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.