How to do Migration when Generate database from model in Entity Framework Model First?

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.

Up vote 5 down vote favorite 5 share g+ share fb share tw.

I have an existing model and initially generated the database from this model and had populated the existing tables with some data. Now I've added a new table to the model. Is there a way to update the database from the new model without losing all the data in the existing tables?

Thanks. Entity-framework-4 model-first link|improve this question edited Nov 19 '10 at 4:46Morteza Manavi10.6k12235 asked Nov 19 '10 at 3:52user28280730926 86% accept rate.

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. 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.

Thankx very much for info! – user282807 Nov 20 '10 at 6:19 No problem, glad it helped :) – Morteza Manavi Nov 20 '10 at 13:23.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions