Pra*_*nny 5 c# entity-framework ef-code-first ef-migrations entity-framework-6
我对这里的情况很困惑。我需要连接到两个单独的数据库,一个是SQL Server数据库,另一个是MySQL数据库。
我在web.config
文件中有连接字符串。我能够连接到服务器并访问数据。
但是,我需要在两个服务器上同时运行实体迁移。或一一列举,我认为这是不可能的。
这是我的数据库上下文:
// Database 1
public class DatabaseContext : DbContext
{
public DatabaseContext() : base("name=OldDBContext"){ }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { }
public static DatabaseContext Create()
{
return new DatabaseContext();
}
public DbSet<User> UserModel { get; set; }
}
// Database 2
public class NewDatabaseContext : DbContext
{
public NewDatabaseContext() : base("name=NewDBContext") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { }
public static NewDatabaseContext Create()
{
return new NewDatabaseContext();
}
public DbSet<UserData> UserDataModel { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
最初,我只有一个数据库,并且曾经add-migration MigrationName
在程序包管理器控制台中运行,它将通过数据库中的更改创建迁移。
但是现在,当我有两个单独的数据库时,迁移不包含第二个数据库或以后添加的数据库中的任何更改。
请帮忙。任何帮助是极大的赞赏。
谢谢
小智 4
尝试为第二个上下文启用迁移,使用 ContextTypeName 参数
Enable-Migrations -EnableAutomaticMigrations -ContextTypeName
NamespaceOfContext.NewDatabaseContext
Run Code Online (Sandbox Code Playgroud)
它将创建单独的配置。如果发生命名冲突,请重命名 Migrations 文件夹中的配置文件,然后您可以针对特定配置运行数据库更新
Update-Database -ConfigurationTypeName ConfigurationName
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1560 次 |
最近记录: |