Skip to content

Comments

[release/10.0] Restore ordinals when transitioning complex collection entries from Deleted state#37729

Merged
AndriySvyryd merged 2 commits intorelease/10.0from
copilot/fix-entity-state-change-bug
Feb 21, 2026
Merged

[release/10.0] Restore ordinals when transitioning complex collection entries from Deleted state#37729
AndriySvyryd merged 2 commits intorelease/10.0from
copilot/fix-entity-state-change-bug

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Fixes #37724

Description

When changing the state of an entity with a complex collection from Deleted to Unchanged, an InvalidOperationException is 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 Modified instead of Unchanged

How 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.

Copilot AI changed the title [WIP] Fix bug when changing entity state from deleted to unchanged Fix: Restore ordinals when transitioning complex collection entries from Deleted/Added states Feb 18, 2026
Copilot AI requested a review from AndriySvyryd February 18, 2026 02:09
Copilot AI changed the title Fix: Restore ordinals when transitioning complex collection entries from Deleted/Added states Fix: Restore ordinals when transitioning complex collection entries from Deleted state Feb 18, 2026
Copilot AI requested a review from AndriySvyryd February 18, 2026 03:06
Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

@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}

Copilot AI requested a review from AndriySvyryd February 18, 2026 22:33
@AndriySvyryd AndriySvyryd marked this pull request as ready for review February 18, 2026 22:34
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner February 18, 2026 22:34
Copilot AI review requested due to automatic review settings February 18, 2026 22: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 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 Ordinal from OriginalOrdinal when transitioning complex collection entries from Deleted state to prevent validation errors
  • Include quirk mode switch UseOldBehavior37724 for 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 InsertEntry method 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

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

LGTM, but @AndriySvyryd am noticing that only one code path has the quirk.

Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Approved. New feature. Customer reported. Workaround seems non-obvious.

@roji roji removed their assignment Feb 19, 2026
Fixes #37724

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd enabled auto-merge (squash) February 21, 2026 01:24
@AndriySvyryd AndriySvyryd merged commit 59291da into release/10.0 Feb 21, 2026
7 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-entity-state-change-bug branch February 21, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants