1

I created an internet asp.net Mvc 4 application. It used EF5 code first, LocalDB by default. I have the following issues. I put all my tables in data context class MyContext and enabled database migration on it.

  1. UsersContext. I added a field email in the table UserProfile. However, I cannot enable database migration on the default UsersContext since I already enabled migration on MyContext. I had to delete the database and let it recreate UserProfile table (I had to open the user register page first, otherwise it will create UserProfile without field email.)

  2. I published the project to a server with IIS/Sql Server and keep working on the project. However, from time to time it shows the model of UsersContext were changed (not true) and I had to delete the database on the live server and let it recreate the database.

  3. Sometimes it create the same index twice on a table in MyContext and it failed the migration. And I had to delete the database again for recreating.

How to prevent the above issues? Should database migration be disabled after go live? How to apply the Model/DB changes?

ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • You should use only one context. See the following answer http://stackoverflow.com/questions/5693843/entity-framework-multiple-object-contexts – Julian Shaw Mar 01 '13 at 11:03
  • The `UsersContext` was created by MVC template scaffold. Should I rename the class in `AccountModel`? – ca9163d9 Mar 02 '13 at 06:55

0 Answers0