本文介绍两个概念,防数据库自动删除,这是由于在code first模式下,当数据实体发生变化时,会对原来数据库进行删除,并将新数据表添加进来,但这对于我们的运营环境数据库,是万万不能接受的,第二个问题是数据迁移问题,当你有新的实体建立后,如何响应到数据库,这成为一个问题,当然实现也很简单,我们直接使用migrations工具即可.
一 防数据库删除
将你的业务DbInitializer的基类改成CreateDatabaseIfNotExists即可解决这个问题,这是在数据初始化时需要做的事,一般地,我们会选择当实体有变化时,自动更新数据库,但这样做影响比较大,所以我们不提倡使用.
public class ManagerInitializer : CreateDatabaseIfNotExists<ManagerContext>
{
protected override void Seed(ManagerContext context)
{
//初始化代码
}
}
二 数据迁移
这个问题也是必须要解决的,我们的实体添加后,数据库并没有对应的表,我们就需要使用migrations命令来对数据库进行更新,具体操作如下
1 开启migrations功能
enable-migrations -force
2 添加迁移版本
add-migration 名称后缀
我们每次修改实体后,都应该使用这个add-migration来升级历史版本
3 更新数据库
update-database
4 程序运行成功后,如图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/4AAACnCAIAAAAnlxA4AAAcW0lEQVR4nO3dP44sx5HH8T5JH0EH4R10iOVBZBLYUzxvCdKSLRky5FGQ23zAChCwAJ0HGWvMsKcmI+IXv6yq/v9tfDCoqc7KjIzMGUYXe/odTr9+BQAAAPD0DjePAAAAAMAVrC/9j8fj8XiMZ4aTW/q/0Jwv17NI1JUHBQAAAAab7vqn5ey91bi3jefesgEAAICXRen/zKMDAAAAZx+l//JNKcfFY9l6OFO1Gcaoen47mY6VvkPmGB5VSCJC0bOYe5WQKra2q+F4XdgAAACA7730XxajWw5OofRP28QGy69mP7EaduIxezaDb+0yi+1hAAAAAB+lf7xjPRwsm+k2ywGc++Uno/Q/hSo57TC9X56OGL915j6bX3+sduLc+AcAAMAW413/s93v+ldm7/o7Zy5R+pvTWT3W1EwBAACAWeN7/c8l+HA8tInNhmfj/fKpu/6ik3ToqtnypAimahCHm6rC1wWjp3/zHQMAAIAH9TD/pNdQB988HgAAAOCxP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AABeAqU/AAAA8BIo/QEAAICXQOkPAAAAvITDP/55eixfv/4LAAAAwKzDfx7qQekPAAAArEPpDwAAALwESn8AAADgJTxb6f+Xv/795jkFAAAA7tBQ+v/0/Xc//HI+fv9Hfr//qTyzuHB46pcfvkuaXbb0/8tf/07pDwAAAKQ+Sv9ffvjueDwefy/9f/r+vXI/1/DxzKfK//c2bx2cG1+t9H+r+yn9AQAAgNTnu/6//PDde+m/KN3fT8YzdekfG0w+fvzxx/9aPH788Udd+p/rfkp/AAAAIGWU/u/H8cxw5ccbfna55f/ly5e3uv/Lly/nk2npv6z7Kf0BAACA1F6lf+xE/GHARPW/rPur0v8rd/0BAACAzk5v+IldLN4CtOOb/nmvPwAAALBOVfpP/pnv+XFudPXS/yuf8AMAAADUwif8fLxHZ+rDPc99nP93wO+Nt/2971Tp/5XP9QcAAAAKz/ZPegEAAABIUfoDAAAAL+Hwj3+eHsvNUwYAAAA8osO///1/AAAAAJ4epT8AAADwEv4fZmfOIbrezasAAAAASUVORK5CYII=" alt="" />
这时你查看自己的数据库,新加的实体已经自动添加到数据库了,呵呵.
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO0AAAC/CAIAAACdacwkAAAPuUlEQVR4nO2dfWxV5R3Hu/21jBgTg0gIiug0MZDoIrjJJoqbS+NLNEJMBBeSGsesTBSxS1dmlEKNLXJN52XQUottWbm9TXFQK261uCmWIQYV8WV0NvTSV1q4k9K3e8PZH1fvDud5Oc95uc85zznfT27I6XOf85xzf+dzf33OOT9O8zQdz7PRGOytfSr5/p2jxwtHE5vHTteNdpcmP3xg5M0rB3d/r6cu78SO70fXL6OumHcxrPHtIT6ypa2zhs3RpwDiXBR6lq8cj9+oXs33eMsz99E3nJdn+NfCTnP7698VGdnS1rOdOQtAPk49bqmy6fG3m7d17MU9dj4aq7O9byDIEU49jkdXueux4Rc0+avc9Jc46y2R+YDp9IDcGU5nIA2Kx+TM1YnHZYV38TZPiMVa4Kwl8q7IfEDETlY+xhTZW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EqiGWXH9MXTa0YF7hIaqGWP7zjzVhoQXbgYuoGmLJzz+mbovswFrR5ocEwqgaYpn1x3o4KRnzCg9RNcSSn39s6SRPw3medFQNsfznH2cR8RIeS0bVEMusP86gvy5hWOB05ncDbhGKEDuvPzZcXCPb9e+SjW5/IGAEIQZBAB6DIACPQRCAxyAIhMVj5/XHpmdvgneqxS9l4ARRnFBEynn9sWZLXJHb19RBLN1zAZq6HkuuPzYkUUG9WKLzNRW5RwgMqBoayfXHhgVNzCrBmQbZB/nYKqqGxpPnH5Nb1C+QqpE/kv05g5O7QW0HWkg8dqX+mPV7n1TQxpzBMCDysVVUDY3k+uM8sfkxPx9rtPyNfOwKqoZG8vOPqWlV/y+5J+SP1Bb+5pCPBVE1NJLrjw2QBlPb7eVjan/AR9Uwya8/ZuVjVh9WB+pb5FpkTzjNQdXQSH7+MdVOJ/MK0/kxdSiozCIUcXHr+cca91KaaWdNIB8bhDaIDo9ZIC4gCMBjEATgMQgC8BgEAfU8frn5dEXTUEXT0Eu7h16oGyzaMVD4av/KzX1LN/Xmrz91e1Fi8bMJr/cRyOZ/koasK9yb+eIAAAAASUVORK5CYII=" alt="" />
值得注意的是,通过这种方法进行数据库迁移,数据库的原数据是不会丢失的,即使你在原来的表上添加字段,老数据也不会丢,新字段会有默认值.
对于EF7来说,它只支持Code First模式,所以这种模式在dotnet框架里将会成为主流!
补充:
最近有朋友问我在服务器上如何进行数据的更新,即在生产环境如何使用迁移,可以读一下我的这篇文章<EF架构~CodeFirst生产环境的Migrations>
EF架构~CodeFirst数据迁移与防数据库删除的更多相关文章
-
EF CodeFirst数据迁移与防数据库删除
1 开启migrations功能 enable-migrations -force 2 添加迁移版本 add-migration 名称后缀 我们每次修改实体后,都应该使用这个add-migration ...
-
EF架构~Migration数据迁移的执行顺序
回到目录 对于单个分支项目来说,只要你生成一个migration的版本,就会有一个时间戳文件的对应,而在update-database时,会从最小的时间开始,一直执行到当前版本的migration,而 ...
-
EF架构~CodeFirst生产环境的Migrations
回到目录 Migrations即迁移,它是EF的code first模式出现的产物,它意思是说,将代码的变化反映到数据库上,这种反映有两种环境,一是本地开发环境,别一种是服务器的生产环境,本地开发环境 ...
-
EF架构~codeFirst从初始化到数据库迁移
一些介绍 CodeFirst是EntityFrameworks的一种开发模式,即代码优先,它以业务代码为主,通过代码来生成数据库,并且加上migration的强大数据表比对功能来生成数据库版本,让程序 ...
-
EF Code-First数据迁移
Code-First数据迁移 首先要通过NuGet将EF升级至最新版本. 新建MVC 4项目MvcMigrationDemo 添加数据模型 Person 和 Department,定义如下: usi ...
-
【EF】EF Code-First数据迁移
Code-First数据迁移 首先要通过NuGet将EF升级至最新版本. 新建MVC 4项目MvcMigrationDemo 添加数据模型 Person 和 Department,定义如下: usi ...
-
Entity Framework CodeFirst数据迁移
前言 紧接着前面一篇博文Entity Framework CodeFirst尝试. 我们知道无论是“Database First”还是“Model First”当模型发生改变了都可以通过Visual ...
-
如何将MongoDB数据库的数据迁移到MySQL数据库中
FAQ v2.0终于上线了,断断续续忙了有2个多月.这个项目是我实践的第一个全栈的项目,从需求(后期有产品经理介入)到架构,再到设计(有征询设计师的意见).构建(前端.后台.数据库.服务器部署),也是 ...
-
codefirst数据迁移技术,在保留数据库数据下实现对模型的修改并映射到数据库
一前言 这是我的处女作,写的不好的地方还望指出共同讨论.EF的数据访问方式有三种DbFirst,ModelFirst,还有本文要提到的CodeFirst 三者都是以ORM的方式建立.本人之前学习的.n ...
随机推荐
-
Python成长笔记 - 基础篇 (十二)
本节内容 ORM介绍 sqlalchemy安装 sqlalchemy基本使用 多外键关联 多对多关系 表结构设计作业 主题:学员管理系统 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的 ...
-
c++ 头文件
可以将程序分为二部分: 头文件:包含结构声明和使用这些结构的函数的原型 源代码文件: 包含与结构有关的函数的代码 不要将函数的定义或变量的声明放在头文件里, 一般头文件可以包含以下内容 >函数原 ...
-
css布局之三列布局
网站上使用三列布局的还是比较多的,不过三列和两列有些相似: 1.自适应三列 <!DOCTYPE html> <html lang="en"> <hea ...
-
[转]配置mysql允许远程连接的方法
配置mysql允许远程连接的方法 vim /etc/my.cnf注释这一行:bind-address=127.0.0.1 ==> #bind-address=127.0.0.1保存退出.mysq ...
-
office 2013 产品秘钥
9RN4T-JPBQV-XQMC9-PM9FP-PGWP9 TKX7J-VDN26-Y2WKQ-7MG8R-X2CC9 N9M8X-QDKGK-W27Q6-2GQYT-TJC9K 4VNXV-F7PB ...
-
转--Android:TextView属性大全
android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all) android ...
-
JavaScript最佳实践:可维护性
代码约定 一.可读性 代码缩进 包含注释 二.变量和函数命名 变量名应为名词如car或person 函数名应该以动词开始,如getName().返回布尔类型值的函数一般以is开头,如isEnable( ...
-
gridView AspNetPager 翻页时 弹出窗体关闭报错
gridView AspNetPager 翻页后,你右击刷新或F5会发现弹出一个刷新页面. 这是因为默认翻页都是用dopostback方式回发的.因为这时的页面已经不是原来的页面.所以会弹出提示. 这 ...
-
[转]SQL语句:Group By总结
1. Group By 语句简介: Group By语句从英文的字面意义上理解就是“根据(by)一定的规则进行分组(Group)”.它的作用是通过一定的规则将一个数据集划分成若干个小的区域,然后针对若 ...
-
input文本框禁止修改文本&mdash;&mdash;disabled和readonly属性的作用及区别
1.input文本框禁止修改文本 disabled属性:<input type="text" name="name" value="xxx&qu ...