简体   繁体   English

实体框架4.3合并多个数据库/上下文

[英]Entity Framework 4.3 merge multiple databases/context

We are using Entity Framework 4.3 Code First. 我们正在使用Entity Framework 4.3代码优先。 We have three databases. 我们有三个数据库。 For each database we have one DbContext. 对于每个数据库,我们都有一个DbContext。 In the first database we have some legacy tables/sql. 在第一个数据库中,我们有一些旧表/ sql。 Overall there are approx. 总体上大约有。 70-80 tables/entities. 70-80个表/实体。

In future we want use EF 4.3 Migration. 将来我们希望使用EF 4.3迁移。

  • Can we merge all three database to one and keep our three DbContext classes? 我们可以将所有三个数据库合并为一个,并保留三个DbContext类吗?
  • Is it better to also merge the DbContext classes? 合并DbContext类是否更好?
  • Can EF 4.3 handle this? EF 4.3可以处理吗?

If you want to use 3 context types you should still use 3 databases. 如果要使用3个上下文类型,则仍应使用3个数据库。 Database migrations are dependent on context type and migration for three context types will not work on single database (or it will cause a lot of trouble including complete manual handling of migration code). 数据库迁移取决于上下文类型,并且三种上下文类型的迁移将无法在单个数据库上进行(或者它将引起很多麻烦,包括对迁移代码的完全手动处理)。 As alternative you can merge all your databases to single database you must also merge are context type to single one. 作为替代方案,您可以将所有数据库合并到单个数据库,还必须将上下文类型合并到单个数据库。 The choice is up to you. 这个选择由你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM