当前位置:Gxlcms >
数据库问题 >
Entity Framework Code-First(18):Turn off DB Initializer
Entity Framework Code-First(18):Turn off DB Initializer
时间:2021-07-01 10:21:17
帮助过:2人阅读
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
标签: