码迷,mamicode.com
首页 > 数据库 > 详细

Entity Framework Code-First(18):Turn off DB Initializer

时间:2016-07-05 19:01:27      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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, 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!