AC4 AC4 - 2 days ago 4
C# Question

EF 6 programmatic Migration with custom connection string

I have an EF6 code first implementation with migrations enabled and a single initial migration. I created a method to programmatically run the migration that looks like the following:

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


When I got to testing I have several configured connection strings in the App.config. My Question:

How do I tell the DbMigrator what connection string to use?

update:
I suppose the catch is doing this without extending DbMigrator.

AC4 AC4
Answer

So unless someone comes up with a better answer: In EF6 there is no working way as of EF 6.1.3 to specify runtime connection strings for programmatic database migrations. I think the only thing I can see is that I will need to generate an sql script and programmatically run it at time of database setup. The issue with this is that I either have to compile in the text or deploy it with the binary.

Comments