Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

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

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
Copilot AI requested a review from AndriySvyryd December 17, 2025 23:45
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
Copilot AI requested a review from AndriySvyryd December 18, 2025 01:19
@AndriySvyryd AndriySvyryd changed the base branch from release/10.0 to main December 19, 2025 02:39
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-update-many-to-many-relationship branch from dbe96f9 to 93683a8 Compare December 19, 2025 03:05
@AndriySvyryd AndriySvyryd changed the title Partial Fix: Prevent marking primary key properties as modified during foreign key propagation Prevent marking primary key properties as modified during foreign key propagation Dec 19, 2025
@AndriySvyryd AndriySvyryd marked this pull request as ready for review December 19, 2025 03:07
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner December 19, 2025 03:07
Copilot AI review requested due to automatic review settings December 19, 2025 03:07
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 #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 GetPropertiesWithMinimalOverlapIfPossible to 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>
@AndriySvyryd AndriySvyryd force-pushed the copilot/fix-update-many-to-many-relationship branch from 93683a8 to 40a0611 Compare December 19, 2025 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue when trying to update some entities that are in a many to many relationships with a favourite child

2 participants