Amir
Amir

Reputation: 349

Nuget CodeFirst EntityFramework Migration or Sync DB

I have been trying ASP.NET MVC 3 using Code-First approach with EntityFramework. There are couple of issues I am facing.

  1. How do I sync the database if schema changes and/or I update my model. Right now i have to delete and re-create the database thus loose all my data. Is there a package available i can use to automatically update the schema. In one of the demos I saw Scott Hanselman using "EntityFramework.Migration" package. I guess that is not released use. Any alternatives?

  2. MvcScaffolding recreates all View/Controllers. Is there a way to preserve CSS Styling in Views if the MVCScaffolding is executed and views are re-created.

Thanks in advanced.

Upvotes: 2

Views: 1419

Answers (3)

Korayem
Korayem

Reputation: 12507

For Scaffolding issue, just change the scaffolding templates themselves so they contain the CSS classes. this way, whenever you re-scaffold, the CSS classes will be there.

More about this here

Upvotes: 0

jhorback
jhorback

Reputation: 833

There are various tools to generate change scripts for databases. As far as entity framework itself, there is the soon to come EntityFramework.Migrations that will also handle this.

http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx

I am not sure about your second question. I personally do not use the automatic generation of views, however, I believe you should be able to modify a T4 template to generate your views the way you want.

Upvotes: 2

DDiVita
DDiVita

Reputation: 4265

Regarding your data loss issue, look into using the database initializer classes. You can seed data each time your model changes. I know this is not ideal, but it is all we have right now with EF 4.1. You can use something like Red Gate's SQL tool-belt to keep environments synced. As part of the package, you can sync data. You can always back-up the scripts created by SQLToolbelt.

Upvotes: 1

Related Questions