2

I am developing a C# application using entity framework 4 with a model first approach (I am having a model where I generate my DB tables and classes from).

What is the best way to periodically change a DB schema (table definitions, etc.), everytime a change request comes from a customer? (Dropping the whole DB and apply generated model SQL to it is obviously not an option, because all the data inside the DB gets lost.)

Hope someone can give me a hint on that.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
AlexLiesenfeld
  • 2,872
  • 7
  • 36
  • 57
  • Isn't Entity doing-it on its own? Update DB schema by the mean you like (SQL ALTER script I guess), then right-click and update model from DB? Maybe I misunderstood your question and it has nothing to do with Entity : general DB update use-case ? – Kek Jul 06 '12 at 18:53

2 Answers2

1

For our model-first database updates, we shoot the generated database into a second, 'diff' database. Then we generate an alteration script using a tool like Open DB diff: http://opendbiff.codeplex.com/ or redgate's SQL comparer: http://www.red-gate.com/products/sql-development/sql-compare/.

The generated scripts will generally create a safe database export, and retain your data. However it is always a good idea to check what the generated scripts actually do, to prevent any data loss.

Olaf
  • 879
  • 6
  • 19
0

Database project. You can do schema compares against your local or dev database, and then generate alters against your production databases. Easy and source controllable as well.

Ryan Bennett
  • 3,404
  • 19
  • 32