Entity Framework 之Code First自动数据迁移
2016-06-09 21:30
423 查看
using MvcShopping.Migrations; using MvcShopping.Models; using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; namespace MvcShopping { public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { //Global.asax.cs配置自动数据迁移 Database.SetInitializer(new MigrateDatabaseToLatestVersion<MvcShoppingContext, Configuration>()); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); } } }
namespace MvcShopping.Migrations { using System; using System.Data.Entity; using System.Data.Entity.Migrations; using System.Linq; /// <summary> /// ~/Migrations/Configuration.cs /// </summary> internal sealed class Configuration : DbMigrationsConfiguration<MvcShopping.Models.MvcShoppingContext> { public Configuration() { AutomaticMigrationsEnabled = true; //开启 ①修改数据模型 ②项目重新生成 ③F5调试 ④查看数据库 AutomaticMigrationDataLossAllowed = true; } protected override void Seed(MvcShopping.Models.MvcShoppingContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // } } }
相关文章推荐
- 2015ACM/ICPC亚洲区沈阳站 Meeting HDU 5521 (优先队列搜索)
- 游戏自动按键脚本2:海空战斗
- sg函数与博弈论
- CSS:给 input 中 type="text" 设置CSS样式
- C++:连接字符串(不使用库函数)
- 编解码学习笔记(二):codec类型
- leetcode-java-22. Generate Parentheses
- [Nutch]限制Hadoop结点连接
- 《剑指offer》:[26]复杂链表的复制
- 同步异步
- 36. Valid Sudoku
- 26. Remove Duplicates from Sorted Array
- 112. Path Sum
- Java反射(一)
- webstorm下载地址分享
- POJ 3974 Palindrome manacher
- 不用+、-、×、÷做加法
- 《剑指offer》:[25]二叉树中和为某一值的路径
- Zephyr 教程:应用程序基础
- 容器 集合 数据结构