c# - 带有自定义连接字符串的 EF 6 程序化迁移

标签 c# .net entity-framework entity-framework-6 .net-4.5

我有一个 EF6 代码优先实现,启用了迁移和一个初始迁移。我创建了一个以编程方式运行迁移的方法,如下所示:

public void RunMigration()
{
    var migrationConfiguration = new DataAccess.Migrations.Configuration();
    var migrator = new System.Data.Entity.Migrations.DbMigrator(migrationConfiguration);
    migrator.Update();
}

当我开始测试时,我在 App.config 中配置了几个连接字符串。我的问题:

如何告诉 DbMigrator 使用什么连接字符串?

更新: 我想问题是在不扩展 DbMigrator 的情况下执行此操作。

最佳答案

我用

var migrator = new DbMigrator(new DbMigrationsConfiguration { TargetDatabase = new DbConnectionInfo("MyConnectionStringHere")});
migrator.Update();

关于c# - 带有自定义连接字符串的 EF 6 程序化迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34317589/

相关文章:

c# - 带有通用参数的 dotnet .net core 2 OrderBy/OrderByDescending

.net - 安装 Entity Framework 7 RC1的问题

c# - 从 C#.NET Winform 应用程序在 SQL Server 中重复查询

.net - 如何将鼠标滚轮事件传输到 WindowsFormsHost?

.net - MVC EF 上下文实例

c# - 如何从 ASP.NET Core 2.0 中的自定义中间件请求身份验证

c# - 未处理 Gridview 事件排序

wpf - Catel + EntityFramework

c# - 序列化两个互相引用的对象

entity-framework - 如何将 dll 部署到系统的 GAC 并在程序启动时检查它们是否存在?