Repository navigation
[release/11.0] Preserve generated values when replacing entries - #39629
Merged
AndriySvyryd merged 3 commits intoNov 16, 2026
Merged
Conversation
- Preserve values from added entries after a shared row deletion\n- Cover owned replacements, re-added entities, and shared writers\n\nFixes #39617\n\nCo-authored-by: Copilot App <223556219+Copawat@users.noreply.github.com>
- Explain why deleted entries are not current writers Fixes #39617 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Code coverage overviewLanguages: C# C# / code-coverage
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the fix preventing deleted-entry placeholders from overwriting generated-on-add values.
No open issues 🎉
What changed in this PR
This servicing fix addresses #39617 in EF Core’s relational update pipeline, preventing deleted entries’ null placeholders from overwriting generated-on-add values when an entity is replaced.
Changes:
- Tracks whether a shared-column value came from a deleted entry while preserving modified-writer precedence.
- Adds an AppContext switch to restore the previous behavior.
- Adds three parameterized regression tests covering owned-instance replacement, same-key re-addition, and modified shared-column values.
| File | Description |
|---|---|
| test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs | Adds synchronous and asynchronous checks of tracked and persisted replacement values. |
| src/EFCore.Relational/Update/ModificationCommand.cs | Distinguishes deletion placeholders from current writer values and adds the compatibility switch. |
Review effort: Balanced
artl93
approved these changes
Nov 14, 2026
artl93
left a comment
Member
There was a problem hiding this comment.
regression. customer reported. approved.
cincuranet
approved these changes
Nov 16, 2026
cincuranet
approved these changes
Nov 16, 2026
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #39617
Description
When a deleted entity and its replacement share a row, EF can mistake the deleted entity's null placeholder for a value to propagate to the replacement. Track whether the current value came from a deletion, while preserving the precedence of a modified shared-column writer.
Customer impact
Replacing an owned instance or deleting and re-adding an entity with the same key can cause
SaveChangesto throw. Nullable generated-on-add values can instead silently become null in the tracked entity while the database retains the original value; subsequent operations may act on incorrect in-memory data. Configuring affected properties withValueGeneratedNever()is a workaround, but changes insert behavior and is not obvious.How found
User reported on EF Core 11.0.0.
Regression
Yes, from 10.0.*, Introduced by #37751.
Testing
Three new parameterized relational tests (12 cases per provider).
Risk
Low, the change affects shared-column value propagation across relational providers, but a quirk mode was added.