[5.0.1] Migrations: Skip DbFunctionAttributeConvention when creating model for history repository #23452
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.
Resolves #23312
Description
When generating the script to create migration history table, we use a model builder to generate the model. This model builder is decoupled from the application DbContext so that it won't include application entity types in the model. However, this decoupling is broken in 5.0 because we still discover methods on DbContext annotated with DbFunctionAttribute. If the DbFunction is targeting table valued function (TVF), then we add that as an entity type to the model. This causes an incorrect model to be built for the history table.
Customer Impact
Customers who have TVF declared using DbFunction attribute on their DbContext will get error when applying first migration or generating migration script from first migration. We create the migration history table in first migration if it does not exist.
How found
Reported by customer on 5.0 release.
Test coverage
Updated existing tests which were verifying the scripts for migration history table to use actual DbContext which would match customer scenarios.
Regression?
No. TVF is a new feature in 5.0. Earlier even though we would have added DbFunctions to the model, it wouldn't have added additional entity types.
Risk
Low. The model is not supposed to discover any entity types. By removing convention it would not remove something which is required. Also there is a quirk mode to revert to previous behavior.