Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework: How to update database when modifying Model

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

like image 940
Fabiano Avatar asked Jul 01 '10 13:07

Fabiano


People also ask

How do I update Entity Framework model from database first?

Right-click anywhere on the design surface, and select Update Model from Database. In the Update Wizard, select the Refresh tab and then select Tables > dbo > Student. Click Finish.

How do I update my ef core model after database change?

Right-click anywhere on the design surface, and select Update Model from Database... In the Update Wizard, select the Refresh tab and select your table then click Finish button.


1 Answers

Best way that I've found so far is to update the database first, for example adding a column to a table and then update the model from the database. This works well for small changes.

like image 141
Klas Avatar answered Sep 27 '22 23:09

Klas