How to disable code-first feature in EF (MVC4 Visual Studio 2012)

asp.net-mvc-4 ef-code-first entity-framework visual-studio-2012

Popular Answer

When you alter your model, you may use Code First to make sure that your database never gets modified or overwritten by setting the database initializer tonull :

Database.SetInitializer<MyDbContext>(null);

This static method is part of theDatabase class, such as in global.asax or a static constructor of your context class, should be called at the start of your application. By doing this, you have to manually adjust the model class and database structure to match.

The Reverse Engineer function can also be used to build a Code First model from an existing database. Here is an explanation: http://msdn.microsoft.com/en-us/data/jj200620

Alternatively, you can utilize the Database First technique, which is described here: http://msdn.microsoft.com/en-us/data/jj206878, if you don't want to use Code First at all and prefer to work with a model designer.

Here is a summary of all the available choices: http://msdn.microsoft.com/en-us/data/ee712907.aspx

23
6/1/2013 11:13:59 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow