views:

71

answers:

1

Hi

In Entity Framework 4 there are the options "Update Model from Database" and "Generate Database from Model". But what I'm missing is an option like

Update Database from Model

which reflects the changes made in the model (e.g. adding a new Property or Navigation-Property) by modifying the database schema (e.g. adding a new column). without losing its content.

Does someone know a way to achieve this or is there a t4 template that can perform a schema update without dropping existing tables? (I'm using Visual Studio 2010, .Net 4.0 and SQL Server 2008)

Thanks

A: 

This should happen through normal use of the Entity framework:

DataBaseModel model = new DataBaseModel();
model.TableName.Add(tableRow);
model.SaveChanges();

Basically calling SaveChanges() will update your database to match any changes you made to the model.

Note: untested code because my visual studio had crashed, again :(

MrFox
He's changing schema. You're changing data. Different worlds.
Craig Stuntz