Entity Framework 4.1 - Tracking and manually deploying DDL changes using T-SQL
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).
精彩评论