[release/8.0] Don't generate a discriminator in the snapshot if there's no discriminator property. #33622
+157
−62
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 #33605
Description
When an entity type is discovered as part of a TPH inheritance it gets a discriminator value assigned. If the base type is ignored later and a migration is generated EF preserves the discriminator value even though the is no corresponding discriminator property.
Customer impact
When adding another migration in the above scenario EF will generate an operation to drop the non-existing discriminator column, resulting in an error. A workaround is to manually edit the snapshot or the migration, but this would need to be done after every new migration.
While there has only been one report this affects models with an abstract unmapped base type, which is not that uncommon.
How found
Customer reported on 8.
Regression
Yes, from 7
Testing
Test added.
Risk
Low. The fix is in code that only runs as part of a design-time tool.