.Net Mvc Automated Migration 数据迁移

1、打开程序包管理器控制台 PM> enable-migrations –EnableAutomaticMigration:$true

2、项目工程文件中会生成Migrations文件夹

3、找到数据库上下文中的构造函数中,如

public StudentDB() : base("name=StudentDB")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentDB, DataMigrationDemo.Migrations.Configuration>("StudentDB"));
}

4、找到Migrations文件夹下的Configuration.cs,在构造函数中输入   AutomaticMigrationDataLossAllowed = true  如

        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            ContextKey = "DataMigrationDemo.StudentDB";
        }

 

2在

posted @ 2016-12-28 15:20  装饰的梦  阅读(248)  评论(0编辑  收藏  举报