Entity Framework Core Mutiple DbContext Migrations in same database

折月煮酒 提交于 2019-12-11 02:51:59

问题


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:


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.



来源:https://stackoverflow.com/questions/44694649/entity-framework-core-mutiple-dbcontext-migrations-in-same-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!