添加migrations的factory例子
This commit is contained in:
parent
4f6c724636
commit
793e78bd93
|
@ -17,6 +17,7 @@ namespace Sample.Migrations
|
||||||
public class DefaultDesignTimeDbContextFactory: IDesignTimeDbContextFactory<DefaultShardingTableDbContext>
|
public class DefaultDesignTimeDbContextFactory: IDesignTimeDbContextFactory<DefaultShardingTableDbContext>
|
||||||
{
|
{
|
||||||
private static IServiceProvider _serviceProvider;
|
private static IServiceProvider _serviceProvider;
|
||||||
|
[Obsolete("Obsolete")]
|
||||||
static DefaultDesignTimeDbContextFactory()
|
static DefaultDesignTimeDbContextFactory()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
|
@ -30,16 +31,18 @@ namespace Sample.Migrations
|
||||||
{
|
{
|
||||||
op.UseShardingQuery((conStr, builder) =>
|
op.UseShardingQuery((conStr, builder) =>
|
||||||
{
|
{
|
||||||
builder.UseSqlServer(conStr)
|
builder.UseSqlServer(conStr);
|
||||||
.ReplaceService<IMigrationsSqlGenerator, ShardingSqlServerMigrationsSqlGenerator<DefaultShardingTableDbContext>>()
|
|
||||||
.ReplaceService<IMigrationsModelDiffer, RemoveForeignKeyMigrationsModelDiffer>();
|
|
||||||
});
|
});
|
||||||
op.UseShardingTransaction((connection, builder) =>
|
op.UseShardingTransaction((connection, builder) =>
|
||||||
{
|
{
|
||||||
builder.UseSqlServer(connection);
|
builder.UseSqlServer(connection);
|
||||||
});
|
});
|
||||||
op.AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=ShardingCoreDBMigration;Integrated Security=True;");
|
op.AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=ShardingCoreDBMigration;Integrated Security=True;");
|
||||||
|
op.UseShardingMigrationConfigure(op =>
|
||||||
|
{
|
||||||
|
op.ReplaceService<IMigrationsSqlGenerator,
|
||||||
|
ShardingSqlServerMigrationsSqlGenerator<DefaultShardingTableDbContext>>();
|
||||||
|
});
|
||||||
}).ReplaceService<ITableEnsureManager,SqlServerTableEnsureManager>().EnsureConfig();
|
}).ReplaceService<ITableEnsureManager,SqlServerTableEnsureManager>().EnsureConfig();
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue