[5.0.1] Only accept non-default store-generated values #23186
Merged
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 #23180
Description
When propagating store-generated value from the principal entry to the dependent we set the FK store-generated value to
null
if there was any, due to #22603. When accepting the values on the dependent entry we overwrite the propagated value with the "store-generated"null
.EF expects that the properties that currently have the default value to be store-generated. Therefore it is reasonable to only accept the store-generated value if it's different from the default.
Customer Impact
Inserting a non-TPT dependent and two principals or a TPT-dependent and a principal when the principals have store-generated primary keys will result in a navigation to principal being set to
null
.It is possible to manually set the navigation after calling
SaveChanges
as a workaround, but this situation is hard to detect and could lead to data corruption.How found
Reported by user on RC2
Test coverage
This PR includes tests for the affected scenario.
Regression?
No, this issue existed in 3.1, but was made more likely to surface by the introduction of TPT
Risk
Medium. The modified code is used in all SaveChanges scenarios with store-generated values.