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>

 

相关文章:

  • 2021-06-11
  • 2021-08-09
  • 2022-01-24
  • 2021-08-19
  • 2021-07-06
  • 2021-09-12
  • 2021-07-07
猜你喜欢
  • 2021-11-10
  • 2021-12-19
  • 2021-12-03
  • 2022-12-23
  • 2021-07-24
  • 2021-07-29
  • 2021-08-25
相关资源
相似解决方案