Export (0) Print
Expand All

How to: Define a Model with Table-per-Type Inheritance

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic describes how to manually create a conceptual model that has a table-per-type inheritance hierarchy. Table-per-type inheritance uses a separate table in the database to maintain data for non-inherited properties and key properties for each type in the inheritance hierarchy.

Bb738685.note(en-us,VS.110).gifNote:
The recommended way to define a model with table-per-type inheritance is by using the ADO.NET Entity Data Model Tools. For more information, see Walkthrough: Mapping Inheritance - Table-per-Type.

The basic steps for manually defining a model with table-per-type inheritance are as follows:

  1. Define one entity set in the conceptual model that will contain the base entity type and the derived types. For more information, see EntitySet Element (CSDL).

  2. Define derived entity types in the conceptual model by using the BaseType attribute and define only non-inherited properties on the derived types. For more information, see EntityType Element (CSDL).

  3. Map the base entity type and derived types in the same EntitySetMapping element in the mapping specification language (MSL). Map inherited properties to table columns where appropriate. Use the IsTypeOf syntax when setting the value of the TypeName attribute. For more information, see EntitySetMapping Element (MSL).

The following example assumes that you have installed the School sample database and that you have manually configured your project to use the Entity Framework. For more information, see Creating the School Sample Database and Configuring the Entity Framework.

To create the storage model

  1. Add the following XML file to your project and name it School.ssdl.

To create the conceptual model

  1. Add the following XML file to your project and name it School.csdl. Note the following:

    • Only one entity set, Courses, is defined for the three entity types: Course, OnlineCourse, and OnsiteCourse.

    • The OnlineCourse and OnsiteCourse entity types are derived types as indicated by the BaseType attribute in their definitions.

    • The properties defined for the OnlineCourse and OnsiteCourse entity types are only non-inherited properties.

To define the mapping between the conceptual model and the storage model

  1. Add the following XML file to your project and name it School.msl. Note the following:

    • The mapping for the Course, OnlineCourse, and OnsiteCourse entity types is defined in the same EntitySetMapping element.

    • The inherited CourseID properties for OnlineCourse and OnsiteCourse are mapped to the corresponding columns in the underlying database tables.

    • For each entity type mapping, the IsTypeOf syntax is used to indicate the entity type that is being mapped.

See Also

Show:
© 2014 Microsoft