Skip to content

Detect EF Core database provider by keyword match#25295

Merged
EngincanV merged 1 commit intorel-10.2from
fix/ef-core-database-provider-detection
Apr 20, 2026
Merged

Detect EF Core database provider by keyword match#25295
EngincanV merged 1 commit intorel-10.2from
fix/ef-core-database-provider-detection

Conversation

@maliming
Copy link
Copy Markdown
Member

Resolve #25293

The previous switch in AbpDbContext.GetDatabaseProviderOrNull matched Database.ProviderName against a hard-coded set of strings. When the upstream provider assembly got renamed (e.g. Oracle's MySql.EntityFrameworkCore vs the old MySql.Data.MySqlClient), the switch fell through to null and SetDatabaseProvider was never called.

Extracted the mapping into EfCoreDatabaseProviderHelper.GetDatabaseProviderOrNull(string?) and switched to keyword Contains matching, 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).

- 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 switch matching with keyword-based detection via a new EfCoreDatabaseProviderHelper.GetDatabaseProviderOrNull(string?).
  • Updated AbpDbContext.GetDatabaseProviderOrNull to 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.

@maliming maliming requested a review from EngincanV April 20, 2026 10:01
@EngincanV EngincanV merged commit 3502eae into rel-10.2 Apr 20, 2026
7 checks passed
@EngincanV EngincanV deleted the fix/ef-core-database-provider-detection branch April 20, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants