[5.0.3] Use IUpdateEntry.EntityState instead of ModificationCommand.EntityState for entities using table splitting. #23692
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.
Fixes #23668
Description
ModificationCommand.EntityState
is used in many places throughoutCommandBatchPreparer
and in most cases it is the same asIUpdateEntry.EntityState
for the corresponding entry, however when adding an optional dependent to an existing rowModificationCommand.EntityState
isModified
whileIUpdateEntry.EntityState
isAdded
Customer Impact
Adding an optional dependent that is referencing a newly added principal entity or deleting both of them can result in a SQL error as the operations aren't ordered correctly. A workaround would be to call
SaveChanges
immediately after the first operation that should be performed, but this isn't feasible in some scenarios.How found
Customer reported on 5.0.1.
Test coverage
We have added more test coverage in this PR.
Regression?
Yes
Risk
Low. In most cases other cases
ModificationCommand.EntityState
andIUpdateEntry.EntityState
are the same