How to: Update an .edmx File when the Database Changes
[This page is specific to the latest version of the Entity Framework. The latest version is available as the 'Entity Framework' NuGet package. For more information, see Entity Framework Releases and Versioning.]
The Entity Designer uses the Update Model Wizard to update an .edmx file from changes made to the database. The Update Model Wizard overwrites the storage model as part of this process. The Update Model Wizard also makes some changes to the conceptual model and mappings, but it only makes these changes when objects are added to the database. For example, new entity types are added to the conceptual model when tables are added to the database, and new properties are added to entity types when columns are added to a table. For details about what changes are made to the .edmx file, see Changes Made to an .edmx File by the Update Model Wizard.
The Update Model Wizard does the following:
If an object has been deleted from the database, the wizard removes the object from the storage model. Mapping specifications are updated so that objects in the conceptual model are not mapped to storage elements that no longer exist. Existing conceptual model objects are not deleted.
If an object has been added to the database (or was not included in the previous model), you can choose to add the object to the model. The storage model is updated with the newly-added object. In the case of a table or view (but not a stored procedure), a corresponding entity type is created and mapped to the object.
If an object has been updated, the wizard updates the object definition in the storage model. If any new columns have been added to a table or view, the corresponding entity types are updated with matching properties. If the corresponding entity types are part of an inheritance hierarchy, only the affected entity closest to the root of the hierarchy is updated with matching properties. This prevents child entities in the hierarchy from defining the same properties as their ancestors.
To update the .edmx file when the database changes
In the Model Browser , right-click the .edmx file and select Update Model from Database .
The Update Model Wizard starts. If there is no database connection specified, the Choose Your Database Connection dialog box appears. Otherwise, the Choose Your Database Objects dialog box appears.
If the Choose Your Database Connection dialog box appears, specify a database connection. Otherwise, go to the next step.
For details about specifying a connection, see Choose Your Database Connection Dialog Box. When you have specified the connection, click Next to display the Choose Your Database Objects dialog box.
Click the Add tab.
Nodes for tables, views, and stored procedures are displayed. If any objects have been added to the database (or were not included in the previous storage model), you can expand the corresponding node to view the objects that are available to add to the conceptual model.
Note
If an object has been deleted from the conceptual model but has not also been deleted from the storage model, the object will not be available to add to the conceptual model. For more information, see How to: Delete Objects from the Storage Model.
Expand the Tables , Views , and Stored Procedures nodes, and check the objects you want to add to the .edmx file.
Click the Refresh tab.
Nodes for tables, views, and stored procedures that are included in the existing storage model are displayed. Any changes that have been made to these database objects will be reflected in the updated storage model. Changes to the conceptual model are made when columns are added to a table or view.
Click the Delete tab.
Nodes for tables, views, and stored procedures are displayed. If an object has been deleted from the database and was included in the previous storage model, you can expand the corresponding node. The objects in these nodes will be deleted from the updated model.
Click Finish to update the .edmx file with the database changes.
Note
The conceptual model will be updated only for objects that are added to the database. All other changes to the conceptual model must be made manually. For information about updating the conceptual model, see ADO.NET Entity Data Model Designer Tasks.
See Also
Concepts
Changes Made to an .edmx File by the Update Model Wizard
Other Resources
Introducing the ADO.NET Entity Data Model Designer
Build Date:
2013-06-19