Update Model from Database in Entity Framework Database First Approach

In this articel we will see how to update edmx file i.e. model from database. 
In database first approach we first create our database and then update our model accordingly.

We have created two tables in Database to demonstrate how to update edmx file.


We have following tables in database :




The above table is CarCompany table. It has Id and companyName as column. The Id column is the primary key.



The above table is CarModel. It has Id, CarName and CarCompanyId as column. The Id column is primary key. The CarCompanyId is the foreign key which references Id column of CarCompany table.


EDMX File :

We have added a edmx file named Car.edmx. 


Open the edmx file. Right click on the file and click on Update Model from Database option.



On clicking the Update Model from Database, a window opens as shown below :



On the window, select the table checkbox, it shows our two tables from database to update. Also uncheck the checkbox Pluralize or singularize generated object names. Click on Finish button.
On clicking finish button our edmx will be updated with two entities as shown below :


The above are the two entities generated from database. An association is created between CarCompany and CarModel i.e. zero or one to many relation. 

Thus our edmx is updated. 
By this way we update our model from database. This approach is basically used in database first approach.


0 comments:

Post a Comment