Skip to content
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

Automatically determine the database provider and handle on module mapping code #4134

Closed
hikalkan opened this issue May 28, 2020 · 0 comments

Comments

@hikalkan
Copy link
Member

hikalkan commented May 28, 2020

In some cases, module extension methods (example) needs to know the actual database provider being used.

Until now, we provided an option on the extension method call:

builder.ConfigureIdentityServer(options =>
{
	options.DatabaseProvider = EfCoreDatabaseProvider.MySql;
});    

No need to this anymore. ABP Framework automatically determines the provider and sets it on the modelbuilder

protected virtual void TrySetDatabaseProvider(ModelBuilder modelBuilder)
{
var provider = GetDatabaseProviderOrNull(modelBuilder);
if (provider != null)
{
modelBuilder.SetDatabaseProvider(provider.Value);
}
}
protected virtual EfCoreDatabaseProvider? GetDatabaseProviderOrNull(ModelBuilder modelBuilder)
{
switch (Database.ProviderName)
{
case "Microsoft.EntityFrameworkCore.SqlServer":
return EfCoreDatabaseProvider.SqlServer;
case "Npgsql.EntityFrameworkCore.PostgreSQL":
return EfCoreDatabaseProvider.PostgreSql;
case "Pomelo.EntityFrameworkCore.MySql":
return EfCoreDatabaseProvider.MySql;
case "Devart.Data.Oracle.EFCore":
return EfCoreDatabaseProvider.Oracle;
case "Microsoft.EntityFrameworkCore.Sqlite":
return EfCoreDatabaseProvider.Sqlite;
case "Microsoft.EntityFrameworkCore.InMemory":
return EfCoreDatabaseProvider.InMemory;
case "FirebirdSql.EntityFrameworkCore.Firebird":
return EfCoreDatabaseProvider.Firebird;
case "Microsoft.EntityFrameworkCore.Cosmos":
return EfCoreDatabaseProvider.Cosmos;
default:
return null;
}
}

Module extension methods can get it like modelBuilder.IsUsingMySQL()

If it can't determine automatically, you can still call it like modelBuilder.UseMySql(); in the OnModelCreating of your DbContext that overrides it.

So, no need to set it for every module. I marked the DatabaseProvider option of the ConfigureIdentityServer as obsolete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant