-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute #36666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ses inherit DbContextAttribute Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
AndriySvyryd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Rewrite the PR summary using this template:
Fixes #{number}
**Description**
{Issue description}
**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}
**How found**
{Was it customer reported or found during verification? How many customers are affected?}
**Regression**
{Is it a regression from a released version? Which one?}
**Testing**
{How the changes were tested}
**Risk**
{Low/Medium/High, argument why}
test/EFCore.Relational.Tests/Migrations/Internal/MigrationsAssemblyTest.cs
Show resolved
Hide resolved
|
@copilot Continue |
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
... Rewrote the PR description using the requested template format, including sections for Description, Customer impact, How found, Regression, Testing, and Risk assessment. The updated description provides comprehensive details about the fix and its impact.
Completed both requested changes:
All tests are now passing and the changes have been committed. |
artl93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Customer reported regression straightforward fix
Fixes #35590
Description
AmbiguousMatchExceptionis thrown when migration classes inherit from each other and both haveDbContextAttribute. The issue occurs becauseGetCustomAttribute<DbContextAttribute>()finds multiple attributes in the inheritance chain when using the default behavior that includes inherited attributes.Customer impact
Customers who create extended migrations that inherit from other migration classes and apply
DbContextAttributeto both the base and derived classes encounter a runtime exception during migration operations. This prevents normal migration operations from working.The workaround is to avoid using inheritance for migration classes (this isn't a common pattern) or to not apply
DbContextAttributeto base migration classes, but this limits code reuse.How found
Customer reported on EF9.
Regression
Yes, from EF8.
Testing
Test added.
Risk
Low. The change is surgical and only affects the specific attribute lookup behavior. This doesn't change any existing functionality for non-inheritance scenarios.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.