using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.DependencyInjection; using Sample.Migrations.EFCores; using ShardingCore; namespace Sample.Migrations { public class DefaultDesignTimeDbContextFactory: IDesignTimeDbContextFactory { static DefaultDesignTimeDbContextFactory() { var services = new ServiceCollection(); services.AddShardingDbContext( (conn, o) => o.UseSqlServer(conn) .ReplaceService>() ).Begin(o => { o.CreateShardingTableOnStart = false; o.EnsureCreatedWithOutShardingTable = false; o.AutoTrackEntity = true; }) .AddShardingTransaction((connection, builder) => builder.UseSqlServer(connection)) .AddDefaultDataSource("ds0", "Data Source=localhost;Initial Catalog=ShardingCoreDBMigration;Integrated Security=True;") .AddShardingTableRoute(o => { o.AddShardingTableRoute(); o.AddShardingTableRoute(); }).End(); services.AddLogging(); var buildServiceProvider = services.BuildServiceProvider(); ShardingContainer.SetServices(buildServiceProvider); new ShardingBootstrapper(buildServiceProvider).Start(); } public DefaultShardingTableDbContext CreateDbContext(string[] args) { return ShardingContainer.GetService(); } } }