Поделиться через


How to: Update an EDM when the Database Changes

The ADO.NET Entity Data Model Designer (Entity Designer) uses the Update Model Wizard to update an Entity Data Model (EDM) from changes made to the database. The Update Model Wizard overwrites the storage model when updating the EDM based on database changes. 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 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 EDM, see Changes Made to an EDM 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 EDM when the database changes

  1. In the Model Browser, right-click the .edmx file for your model and select Update Model from Database.

    The Update Model Wizard starts. If there is no database connection specified for the EDM, the Choose Your Database Connection dialog box appears. Otherwise, the Choose Your Database Objects dialog box appears.

  2. If the Choose Your Database Connection dialog box appears, specify a database connection for the model. Otherwise, go to the next step.

    For details about specifying a connection, see Choose Your Data Connection Dialog Box. When you have specified the connection, click Next to display the Choose Your Database Objects dialog box.

  3. 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 model), you can expand the corresponding node to view the added objects.

  4. Expand the Tables, Views, and Stored Procedures nodes, and check the objects you want to add to the EDM.

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

  6. 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 model, you can expand the corresponding node. The objects in these nodes will be deleted from the updated model.

  7. Click Finish to update the EDM 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 Entity Data Model Tools Tasks or Entity Framework Tasks.

See Also

Concepts

Changes Made to an EDM by the Update Model Wizard

Other Resources

ADO.NET Entity Data Model Designer
Entity Data Model Tools Tasks
ADO.NET Entity Data Model Designer Scenarios