Multiple DB Contexts in the Same DB and Application in EF 6 and Code First Migrations

Entity Framework 6 added support for multiple DbContexts by adding the -ContextTypeName and -MigrationsDirectory flags. I just ran the commands in my Package Manager Console and pasted the output below… If you have 2 DbContexts in your project and you run enable-migrations, you’ll get an error (as you probably already know): PM> enable-migrations More than … Read more

EntityFramework code-first custom connection string and migrations

If your migration does not work correctly try to set Database.Initialize(true) in DbContext ctor. public CustomContext(DbConnection connection) : base(connection, true) { Database.Initialize(true); } I have similar problem with migrations. And in my solution I have to always set database initializer in ctor, like below public CustomContext(DbConnection connection) : base(connection, true) { Database.SetInitializer(new CustomInitializer()); Database.Initialize(true); } … Read more

Reset Entity-Framework Migrations

You need to : Delete the state: Delete the migrations folder in your project; And Delete the __MigrationHistory table in your database (may be under system tables); Then Run the following command in the Package Manager Console: Enable-Migrations -EnableAutomaticMigrations -Force Use with or without -EnableAutomaticMigrations And finally, you can run: Add-Migration Initial