Fix FK dependency ordering for owned entities with external FK references (WIP)#37694
Draft
Fix FK dependency ordering for owned entities with external FK references (WIP)#37694
Conversation
…ed entities Co-authored-by: AndriySvyryd <[email protected]>
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] Port changes from PR #36769 to main branch
Port PR #36769: Fix FK dependency ordering for owned entities with external FK references
Feb 13, 2026
7 tasks
| } | ||
|
|
||
| [ConditionalFact] | ||
| public void BatchCommands_sorts_FK_dependencies_correctly_when_replacing_owned_entity() |
Member
There was a problem hiding this comment.
@copilot This test passes even without the fix. Modify it so it fails without the fix
Contributor
Author
There was a problem hiding this comment.
Fixed in commit 7fd2d9c. The test now uses actual owned entities (FileEntity owned by DocumentEntity with an FK to ContentEntity) and properly fails without the fix. However, I discovered that the fix from PR #36769 doesn't make the test pass either, suggesting there may be an issue with the original fix or additional work needed to make it work correctly with the owned entity scenario.
Member
Modified the test to use a proper owned entity (FileEntity) with an FK to a non-owner entity (ContentEntity). The test now properly reproduces issue #36059 and fails without the fix. However, the fix from PR #36769 is not making the test pass, suggesting there may be an issue with the fix itself or additional work needed. Co-authored-by: AndriySvyryd <[email protected]>
Copilot stopped work on behalf of
AndriySvyryd due to an error
February 14, 2026 00:16
Copilot
AI
changed the title
Port PR #36769: Fix FK dependency ordering for owned entities with external FK references
Fix FK dependency ordering for owned entities with external FK references (WIP)
Feb 14, 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.
Addresses issue #36059 where FK dependency ordering is incorrect when replacing an owned entity that has a foreign key to a non-owner entity, causing FK constraint violations during SaveChanges.
Problem
When replacing an owned entity that has a foreign key to a non-owner entity, SaveChanges generates commands in incorrect order, causing FK constraint violations. The DELETE of old referenced data executes before the UPDATE that switches the reference.
Example scenario from issue #36059:
Current Status
CommandBatchPreparerTest.cs
CommandBatchPreparer.cs
IsModifiedreturns falseInvestigation Findings
The issue occurs because:
IsModified(foreignKey.Columns, command)returns false at line 768, skipping dependency creationA new fix is being developed that handles FK dependencies for owned entities even when change tracking doesn't detect modifications.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.