-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Prevent marking primary key properties as modified during foreign key propagation #37392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
test/EFCore.Sqlite.FunctionalTests/CompositeKeyForeignKeyFixupSqliteTest.cs
Outdated
Show resolved
Hide resolved
dbe96f9 to
93683a8
Compare
There was a problem hiding this 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
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
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