Uh oh!
There was an error while loading. Please reload this page.
Propagate case-only principal string key updates to dependent FKs - #38585
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes key propagation during relationship fixup when a principal string key value changes only by casing (ordinally different), but the key comparer treats old/new as equal (e.g., case-insensitive comparer). The update ensures dependents’ FK values are kept aligned with the principal’s current key representation, avoiding stale FK casing on inserts/updates.
Changes:
- Update
NavigationFixer.SetForeignKeyPropertiesto propagate string key values when principal/dependent strings are ordinally different even if the key comparer reports equality. - Add a regression test for case-insensitive key comparer scenarios where the principal key casing changes and the dependent FK should be updated accordingly.
- Add a small test-only
CoreTypeMappingwith a case-insensitive key comparer to reproduce the comparer-equal / ordinal-different behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/EFCore/ChangeTracking/Internal/NavigationFixer.cs | Propagates string FK values when ordinal string value differs even if key comparer says equal. |
| test/EFCore.Tests/ChangeTracking/Internal/NavigationFixerTest.cs | Adds regression test and a case-insensitive string key type mapping used by the test model. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
cincuranet
left a comment
There was a problem hiding this comment.
Nice little edge case. :)
Uh oh!
There was an error while loading. Please reload this page.
Fixes#37023
When a principal key changed only by casing (e.g.
"test"→"TEST") beforeSaveChanges, owned dependents could keep the old FK value if key comparison was case-insensitive. This caused inserted dependents to carry stale FK casing even though the principal PK value changed.Key propagation behavior
NavigationFixer.SetForeignKeyPropertiesto propagate when string principal/dependent values are ordinally different, even ifGetKeyValueComparer()treats them as equal.Regression coverage
NavigationFixerTestfor case-insensitive key comparer scenarios:"test","TEST","TEST"after key fixup.Test model setup