Turn off DB Initializer in Code-first:
You can also turn off the DB initializer of your application. Suppose, for the production environment, you don't want to lose existing data and then you can turn off the initializer, as S Hown in the following:
Public classSchooldbcontext:dbcontext { PublicSchooldbcontext ():Base("schooldbconnectionstring") { //Disable initializerDatabase.setinitializer<schooldbcontext> (NULL); } PublicDbset<student> Students {Get;Set; } PublicDbset<standard> Standards {Get;Set; }}
You can also turn off the initializer in the configuration file, for example:
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <appSettings> <AddKey= "Databaseinitializerfortype schooldatalayer.schooldbcontext, Schooldatalayer"value= "Disabled" /> </appSettings></Configuration>
Entity Framework Code-first: Turn off DB Initializer