Try to automatically set the database provider.

pull/4135/head
Halil İbrahim Kalkan 5 years ago
parent c027f49f3e
commit 6d7b49df4d

@ -92,6 +92,8 @@ namespace Volo.Abp.EntityFrameworkCore
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
TrySetDatabaseProvider(modelBuilder);
foreach (var entityType in modelBuilder.Model.GetEntityTypes()) foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{ {
ConfigureBasePropertiesMethodInfo ConfigureBasePropertiesMethodInfo
@ -108,6 +110,40 @@ namespace Volo.Abp.EntityFrameworkCore
} }
} }
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;
}
}
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default) public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{ {
try try

Loading…
Cancel
Save