Detect EF Core database provider by keyword match#25295
Merged
Conversation
- Extract provider name mapping into EfCoreDatabaseProviderHelper - Match provider names by Contains instead of exact switch, so newer assembly names (e.g. MySql.EntityFrameworkCore) are recognized without code changes - Add unit tests covering real provider assemblies and string fallbacks
Closed
1 task
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes EF Core provider detection in AbpDbContext so it continues to work when upstream EF Core provider packages rename/adjust their provider name strings (e.g., Oracle MySQL provider), preventing SetDatabaseProvider from being skipped.
Changes:
- Replaced exact string
switchmatching with keyword-based detection via a newEfCoreDatabaseProviderHelper.GetDatabaseProviderOrNull(string?). - Updated
AbpDbContext.GetDatabaseProviderOrNullto delegate to the helper. - Added unit tests and test-package references to validate detection across multiple EF Core providers (including case-insensitive and “string only” providers).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | Uses the new helper instead of hard-coded provider-name strings. |
| framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProviderHelper.cs | Centralizes provider-name detection using case-insensitive keyword matching. |
| framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProviderHelper_Tests.cs | Adds coverage for real provider assemblies + string-level edge cases. |
| framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo.Abp.EntityFrameworkCore.Tests.csproj | Adds EF Core provider package references needed for the new tests. |
EngincanV
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolve #25293
The previous switch in
AbpDbContext.GetDatabaseProviderOrNullmatchedDatabase.ProviderNameagainst a hard-coded set of strings. When the upstream provider assembly got renamed (e.g. Oracle'sMySql.EntityFrameworkCorevs the oldMySql.Data.MySqlClient), the switch fell through tonullandSetDatabaseProviderwas never called.Extracted the mapping into
EfCoreDatabaseProviderHelper.GetDatabaseProviderOrNull(string?)and switched to keywordContainsmatching, so renamed/forked provider packages are still detected without changes to the framework.Added unit tests that verify the mapping against the real provider assemblies (SqlServer, PostgreSQL, MySQL (Oracle), Oracle, Sqlite, InMemory) plus string-level tests for the providers not referenced as packages (Pomelo MySQL, Devart Oracle, Firebird, Cosmos).