internal static BaseDbContext GetDbContext(string conString, DatabaseType dbType, List <Type> entityTypes = null) { AbstractProvider provider = GetProvider(dbType); DbConnection dbConnection = provider.GetDbConnection(); dbConnection.ConnectionString = conString; IModel model; if (entityTypes?.Count > 0) { model = DbModelFactory.BuildDbCompiledModel(dbType, entityTypes); } else { model = DbModelFactory.GetDbCompiledModel(conString, dbType); } DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); provider.UseDatabase(builder, dbConnection); builder.EnableSensitiveDataLogging(); builder.UseModel(model); builder.UseLoggerFactory(_loggerFactory); return(new BaseDbContext(builder.Options)); }
public GenericDbContext GetDbContext(DbContextParamters options) { AbstractProvider provider = GetProvider(options.DbType); DbConnection dbConnection = provider.GetDbConnection(); dbConnection.ConnectionString = options.ConnectionString; DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); builder.UseLoggerFactory(_loggerFactory); provider.UseDatabase(builder, dbConnection); builder.ReplaceService <IModelCacheKeyFactory, GenericModelCacheKeyFactory>(); builder.ReplaceService <IMigrationsModelDiffer, ShardingMigration>(); return(new GenericDbContext(builder.Options, options, _shardingOptions)); }
public static GenericDbContext GetDbContext(GenericDbContextOptions options) { AbstractProvider provider = GetProvider(options.DbType); DbConnection dbConnection = provider.GetDbConnection(); dbConnection.ConnectionString = options.ConnectionString; DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); provider.UseDatabase(builder, dbConnection); builder.ReplaceService <IModelCacheKeyFactory, GenericModelCacheKeyFactory>(); builder.UseLoggerFactory(options.LoggerFactory); options.ContextOptions = builder.Options; return(new GenericDbContext(options)); }
public GenericDbContext GetDbContext(DbContextParamters dbContextParamters, EFCoreShardingOptions eFCoreShardingOptions) { if (eFCoreShardingOptions == null) { eFCoreShardingOptions = _optionsMonitor.BuildOption(null); } AbstractProvider provider = GetProvider(dbContextParamters.DbType); DbConnection dbConnection = provider.GetDbConnection(); dbConnection.ConnectionString = dbContextParamters.ConnectionString; DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); builder.UseLoggerFactory(_loggerFactory); provider.UseDatabase(builder, dbConnection); builder.ReplaceService <IModelCacheKeyFactory, GenericModelCacheKeyFactory>(); builder.ReplaceService <IMigrationsModelDiffer, ShardingMigration>(); return(new GenericDbContext(builder.Options, dbContextParamters, eFCoreShardingOptions)); }