0

We are using Entity Framework 4.3 Code First. We have three databases. For each database we have one DbContext. In the first database we have some legacy tables/sql. Overall there are approx. 70-80 tables/entities.

In future we want use EF 4.3 Migration.

  • Can we merge all three database to one and keep our three DbContext classes?
  • Is it better to also merge the DbContext classes?
  • Can EF 4.3 handle this?

1 Answer 1

3

If you want to use 3 context types you should still use 3 databases. 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.

Sign up to request clarification or add additional context in comments.

4 Comments

Can I add a fourth context for migration? One "Super"-Context with all tables/DbSets for migration and three context for access the data in the application.
It should work but in such case there is no reason to have your additional three contexts. It will only be more error prone to maintain both main context and other contexts.
Thanks for your answer. Are there any performance issues with 70-80 (or more) entites/tables? Therefore I want to keep the three context classes.
The only performance implication is first initialization of the context. Another issues are mostly in the design. Having class with 80 properties doesn't look like a good design but if you want to use migrations you probably doesn't have other option unless you want dig into migration API and try to find if there is some extension point to implement support for multiple contexts in one database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.