public class FirstDbContext : DbContext { public FirstDbContext(DbContextOptions<FirstDbContext> options) : base(options) { } public DbSet<xx> xxxs{ get; set; } public DbSet<xx> xxxs{ get; set; } } public class SecondDbContext : DbContext { public SecondDbContext (DbContextOptions<FirstDbContext> options) : base(options) { } public DbSet<xx> xxxs{ get; set; } public DbSet<xx> xxxs{ get; set; } } public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var connection = @"xxx"; services.AddDbContext<FirstDbContext> (options => options.UseSqlServer(connection)); var secondDbconnection = @"xxx"; services.AddDbContext<SecondDbContext> (options => options.UseSqlServer(secondDbconnection)); }
Add-Migration InitialCreate -Context FirstDbContext -OutputDir MigrationsFirstDbContextMigrations
Update-Database -Context FirstDbContext