且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

怎么办移民时,在实体框架模型首先生成模型数据库

更新时间:2023-02-05 16:29:48

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.

另一种方法是将安装的 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:

怎么办移民时,在实体框架模型首先生成模型数据库