Prevent marking primary key properties as modified during foreign key propagation#37392
Merged
AndriySvyryd merged 2 commits intomainfrom Feb 2, 2026
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix issue updating entities in many to many relationships
Fix: Prevent marking primary key properties as modified during foreign key propagation
Dec 17, 2025
test/EFCore.Sqlite.FunctionalTests/CompositeKeyForeignKeyFixupSqliteTest.cs
Outdated
Show resolved
Hide resolved
Copilot
AI
changed the title
Fix: Prevent marking primary key properties as modified during foreign key propagation
Partial Fix: Prevent marking primary key properties as modified during foreign key propagation
Dec 18, 2025
dbe96f9 to
93683a8
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #37310 where EF Core's navigation fixup incorrectly attempts to mark primary key properties as modified during foreign key propagation when a property is part of both a primary key and a composite foreign key on the same entity.
Key Changes:
- Modified
GetPropertiesWithMinimalOverlapIfPossibleto exclude properties that are part of any key (primary or alternate) from foreign key propagation - Added a comprehensive test case that reproduces the issue with entities having composite keys where PK properties overlap with FK properties
- Appropriately skipped the new test in the SQL Server owned types test suite where it's not applicable
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/EFCore/Metadata/Internal/ForeignKeyExtensions.cs |
Added IsKey() check to prevent modifying key properties during FK propagation |
test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBaseMiscellaneous.cs |
Added test case with Group/User/GroupMember entities demonstrating the fix |
test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBase.cs |
Added model configuration for the new test entities |
test/EFCore.SqlServer.FunctionalTests/GraphUpdates/GraphUpdatesSqlServerOwnedTest.cs |
Skipped the new test as it doesn't involve owned types |
Fixes #37310 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
93683a8 to
40a0611
Compare
249ae47 to
6b86657
Compare
roji
approved these changes
Jan 31, 2026
6 tasks
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.
When a property is part of both a primary key and a composite foreign key on the same entity, EF's navigation fixup tries to change both even though changing only the non-PK portion would be enough.
Fixes #37310