实体框架4.1 - 使用T-SQL跟踪和手动部署DDL更改 [英] Entity Framework 4.1 - Tracking and manually deploying DDL changes using T-SQL

查看:56
本文介绍了实体框架4.1 - 使用T-SQL跟踪和手动部署DDL更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是实体框架概念的新手。我最近实施了一个使用Entity Framework 4.1 Code First Approach的项目。现在我正在修复一些错误,需要我向模型添加更多的属性(导致对DDL的更改),我受限于没有委托实体框架为我重新创建数据库。如果我使用实体框架重新创建数据库,我将放弃现有的数据。我有什么选择?我可以创建一个T-SQL脚本只是为了进行DDL更改并部署它们吗?如何随着时间的推移跟踪这些变化?帮助!!!

解决方案

您是否使用源代码管理?如果是,那是你最后一个问题的答案。




  • 使用源代码控制和标签/标签每个发布的版本,以便您可以轻松获取该版本的代码,并使用它来创建数据库对于该版本。

  • 然后使用当前版本创建数据库(您需要更改一个版本中的连接字符串,以便数据库不覆盖)。

  • 在开发数据库服务器上部署数据库之后,您可以使用一些工具来创建迁移脚本的基础。 Red Gate SQL Compare或VS Studio数据库工具(VS 2010 Premium或Ultimate)提供了这样的功能。这些工具能够比较数据库的架构,并从旧架构到新架构创建升级脚本。

  • 一旦你有升级脚本,你需要测试那个脚本 - 最好是测试它在生产数据库的备份上。该测试的目标是升级数据库的验证和对数据库充满数据的验证。如果不是,您必须修改脚本,或者可能添加一些手动迁移任务。



注释中提到的数据库电源包正是这样(它是依赖的在VS Studio数据库工具上),但只有当您使用EDMX文件(型号为第一​​)时才执行此操作。


I am a newbie to the Entity Framework concept. I recently implemented a project using Entity Framework 4.1 Code First Approach. Now that I am working on a fix for some bugs, the require me to add more attributes to the model (resulting in changes to DDL), I am restricted with not entrusting Entity Framework to recreate the database for me. If I use the Entity Framework to recreate the DB, I will loose my existing data. What are my options? Can I create a T-SQL Script for just the DDL changes and deploy them? How can keep a track of these changes over time? Help!!!

解决方案

Are you using source control? If yes that is the answer for your last question.

  • Use source control and label/tag each released version so you can easily get the code used for that version and use it to create database used for that version.
  • Then use the current version to create database as well (you need to change connection string in one version so that databases do not override).
  • Once you have to databases deployed on your development database server you can use some tool to create basis of migration script. Red Gate SQL Compare or VS Studio Database tools (VS 2010 Premium or Ultimate) offers such functionality. These tools are able to compare databases' schemas and create upgrade script from the old schema to the new schema.
  • Once you have upgrade script you need to test that script - the best is to test it on the backup of production database. The target of this testing is validation of upgraded database and verification that it works on database full of data. If not you must modify script and perhaps add some manual migration tasks.

Database power pack mentioned in comment does exactly this (it is dependent on VS Studio Database tools) but it does it only if you are using EDMX file (model first).

这篇关于实体框架4.1 - 使用T-SQL跟踪和手动部署DDL更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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