添加migrations的factory例子

This commit is contained in:
xuejiaming 2022-07-29 16:26:02 +08:00
parent 4f6c724636
commit 793e78bd93
1 changed files with 7 additions and 4 deletions

View File

@ -17,6 +17,7 @@ namespace Sample.Migrations
public class DefaultDesignTimeDbContextFactory: IDesignTimeDbContextFactory<DefaultShardingTableDbContext>
{
private static IServiceProvider _serviceProvider;
[Obsolete("Obsolete")]
static DefaultDesignTimeDbContextFactory()
{
var services = new ServiceCollection();
@ -30,16 +31,18 @@ namespace Sample.Migrations
{
op.UseShardingQuery((conStr, builder) =>
{
builder.UseSqlServer(conStr)
.ReplaceService<IMigrationsSqlGenerator, ShardingSqlServerMigrationsSqlGenerator<DefaultShardingTableDbContext>>()
.ReplaceService<IMigrationsModelDiffer, RemoveForeignKeyMigrationsModelDiffer>();
builder.UseSqlServer(conStr);
});
op.UseShardingTransaction((connection, builder) =>
{
builder.UseSqlServer(connection);
});
op.AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=ShardingCoreDBMigration;Integrated Security=True;");
op.UseShardingMigrationConfigure(op =>
{
op.ReplaceService<IMigrationsSqlGenerator,
ShardingSqlServerMigrationsSqlGenerator<DefaultShardingTableDbContext>>();
});
}).ReplaceService<ITableEnsureManager,SqlServerTableEnsureManager>().EnsureConfig();
_serviceProvider = services.BuildServiceProvider();
}