博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Code First Migrations数据迁移方法
阅读量:7087 次
发布时间:2019-06-28

本文共 2128 字,大约阅读时间需要 7 分钟。

摘自网络,忘记作者了,对不住了。仅作记录以备用:

1.    To get started just create a simple project, for example a Console Application. After that write the following in the Package Manager Console (In the Visual Studio menu, select View/Other Windows/Package Manager Console). Write the following and hit enter:  PM> Install-Package EntityFramework 2.    After the EntityFramework 4.3 is installed we need to enable the database migration. Only one project in our solution can be enabled. To enable migration just enter the following in the Package Manager Console: PM> Enable-Migrations 3.    Now when all the basic configuration of our Migration is setup, we can start adding a migration. We do that by using the command “Add-Migration”. In this example we will add a new column to our Blog table called “Created”. So in the Package Console Manager we write: PM> Add-Migration AddBlogCreated 4.    Now when we have added our AddBlogCreted migration to just simply add a new column, we want to run our migration. We can do it by using the Update-Database command in the Package Manager Console: PM> Update-Database 5.    The Update-Database will now execute all migrations that is added and not “executed” since last update. The timestamp prefix of the migration files as mentioned earlier is used to execute the migration in a correct order. If we run this command we will now have a new column called “Created” in our Blog table. 6.    If we also want to see the SQL of the migration we can add the –Verbose parameter after the Update-Database: PM> Update-Database -Verbose 7.    To go to a specific migration, we can use the Update-Database and use the –TargetMigration parameter, for example: PM> Update-Database –TargetMigration:"AddBlogCreated" 8.    This will take us to the “AddBlogCreated” migration state. At the moment we are at this state so nothing will happen. We can try it by going back to a previous state, because we only have one migration we need to back to the first state of the migration (initial state), this is done by set the –TargetMigration value to “$InitialDatabase”: PM> Update-Database –TargetMigration:$InitialDatabase

 

转载地址:http://rerml.baihongyu.com/

你可能感兴趣的文章
[Unity3D]Unity3D游戏开发之ACT游戏三连击效果实现综述
查看>>
键盘回车登录的做法
查看>>
优雅的使用python之环境管理
查看>>
取出当前脚本所在位置、文件名
查看>>
【转】每天一个linux命令(14):head 命令
查看>>
Careerdesign@foxmail.com
查看>>
mkdir failed for img Read-only file system
查看>>
写在2015年即将来临之际
查看>>
【UVA】434-Matty's Blocks
查看>>
MyISAM和InnoDB的区别
查看>>
boost.lexical_cast 学习
查看>>
Android中使用第三方jar包
查看>>
应用程序框架实战三十:表现层及ASP.NET MVC介绍(一)
查看>>
后端码农谈前端(HTML篇)第三课:常见属性
查看>>
NPOI系列
查看>>
virtual private catalog
查看>>
Android剪裁图片简单的方法
查看>>
iPhone/Mac Objective-C内存管理教程和原理剖析
查看>>
PRML Chapter 2. Probability Distributions
查看>>
[转]Console命令详解,让调试js代码变得更简单
查看>>