标签:
You can also turn off the DB initializer of your application. Suppose, for the production environment, you don‘t want to lose existing data, then you can turn off the initializer, as shown in the following:
public class SchoolDBContext: DbContext { public SchoolDBContext() : base("SchoolDBConnectionString") { //Disable initializer Database.SetInitializer<SchoolDBContext>(null); } public DbSet<Student> Students { get; set; } public DbSet<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> <add key="DatabaseInitializerForType SchoolDataLayer.SchoolDBContext, SchoolDataLayer" value="Disabled" /> </appSettings> </configuration>
Entity Framework Code-First(18):Turn off DB Initializer
标签:
原文地址:http://www.cnblogs.com/purplefox2008/p/5644357.html