Search code examples
asp.netentity-frameworkcode-first

entity framework code first using existing database


I have started learning Entity framework and have a problem. I have created a code first mvc project and I don't want to drop the database when the model changes. What can I do other than DropCreateDatabaseIfModelChanges in my initializer class so that the database and the tables stays along with the data?


Solution

  • You don't need to use an initializer at all. This is valid:

    Database.SetInitializer<YourContext>(null);
    

    And in your configuration file set AutomaticMigrationsEnabled = false;

    Then you can do the migrations yourself.