Entity Framework Core Mutiple DbContext Migrations in same database

.net-core entity-framework entity-framework-core

Question

In Entity Framework 6 you could specify a ContextKey for a DbContext so that when using one database for multiple DbContexts the Migrations table was aware of what migration targeted what DbContext.

I've spent the last few hours trying to work out how you achieve the same in Entity Framework Core but haven't worked it out and documentation is lacking.

The new Migrations table in EF Core only has two columns - MigrationId, ProductVersion.

I thought HasDefaultSchema was the answer but doesn't seem to be.

Ideas?

1
2
6/22/2017 8:52:50 AM

Accepted Answer

Previously, Entity Framework stored a snapshot of the model in the database. This resulted in Entity Framework having to query the database each time in order to work out what migrations had already run.

In EF7 migration history is stored in a snapshot in code (along with the existing migrations stored in the familiar Migrations folder).

Each time you update the model and create a migration the snapshot file gets updated. Therefore, there is no need for the ContextKey which was used in earlier version of Entity Framework.

Lovely.

4
6/23/2017 6:10:57 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow