怎么办移民时,在实体框架模型首先生成模型数据库 [英] How to do Migration when Generate database from model in Entity Framework Model First

查看:140
本文介绍了怎么办移民时,在实体框架模型首先生成模型数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的模型和最初生成该模型的数据库,并填充了一些数据,现有的表。现在,我已经添加了一个新表到模型。有没有一种方法,而不会丢失所有数据的现有表的更新与新模式的数据库?谢谢你。

I have an existing model and initially generated the database from this model and had populated the existing tables with some data. Now I've added a new table to the model. Is there a way to update the database from the new model without losing all the data in the existing tables? Thanks.

推荐答案

EF的默认数据库生成的工作流创建一个完整的脚本,将您选择每次重新创建数据库的生成模型库... 的这样如果你在你的数据库执行它,你会失去所有的数据。但是,如果你只是创建一个新的实体,并没有改变现有的,那么你仍然可以根据你的模型数据库中,但随后采取的剧本,只运行,致力于为您的新实体的新表中的一部分。

EF's default database generation workflow creates a full script that will recreate your database every time you select Generate Database from Model... so if you execute it in your DB you will lose all your data. However, if you just create a new Entity and did not change the existing ones, then you can still generate database from your Model but then take that script and only run the part that creates the new table for your new entity.

另一种方法是将安装的 <一href="http://visualstudiogallery.msdn.microsoft.com/en-us/df3541c3-d833-4b65-b942-989e7ec74c87">Entity设计数据库发电包 的微软而没有做它在EF4.0发布。当你安装它,改变你的数据库生成流程的为生成迁移TSQL 当你根据你的模型库:

Another way would be to install Entity Designer Database Generation Power Pack from Microsoft which didn't make it to be in EF4.0 release. After you install it, change your database generation workflow to Generate Migration TSQL when you generate Database from your Model:

这篇关于怎么办移民时,在实体框架模型首先生成模型数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆