共用方式為


How to: Create and Delete Inheritance Relationships

Inheritance enables one entity type to be derived from another entity type in the Entity Data Model (EDM). For example, Employee and Customer types can both inherit from the Contact type. In this case, Contact is called the base type. Employee and Customer are called derived types.

An inheritance relationship is represented on the design surface as a line that connects the base type and the derived type. The connector has a hollow arrow at the end that points to the base type.

Note

The ADO.NET Entity Data Model Designer does not allow a type to inherit from itself. That is, the source and target ends must be different.

Create an Inheritance

Creating an inheritance relationship does the following:

  • Adds the inheritance relationship to the design surface.

  • Modifies the part of the .edmx file that defines the conceptual data model.

  • Updates the Mapping Details window.

  • Updates the Model Browser window.

To create an inheritance relationship from the design surface

  1. Right-click an empty area of the design surface, point to Add, and select Inheritance.

    The New Inheritance dialog box appears.

  2. Select the base and derived entity types.

  3. Click OK.

    The inheritance relationship is created.

To create an inheritance relationship using the Toolbox

  1. Select the Inheritance control from the Toolbox.

  2. Click the subtype entity on the designer surface and then click the base type on the designer surface.

    The inheritance relationship is created.

To create an inheritance relationship from a selected entity

  1. Select an entity from the design surface, point to Add, and select Inheritance.

    The New Inheritance dialog box appears. The selected entity is listed as the base entity.

  2. Select the derived entity type.

  3. Click OK.

    The inheritance relationship is created.

To create an inheritance relationship using the Properties window

  1. Select an entity.

  2. From the Properties window, select the base type for the inheritance relationship from the Base Type drop-down list.

    The inheritance relationship is created.

Delete an Inheritance

Deleting an inheritance relationship does the following:

  • Removes the inheritance relationship from the design surface.

  • Modifies the part of the .edmx file that defines the conceptual data model.

  • Sets the Base Type property of the derived types to (None).

  • Updates the Mapping Details window.

  • Updates the Model Browser window.

To delete an inheritance relationship

  • Right-click the inheritance and select Delete.

    -or-

  • Select one or more inheritances and press the DELETE key.

See Also

Concepts

ADO.NET Entity Data Model Designer Overview

Other Resources

Entity Data Model Tools Tasks