How to: Map Inheritance Hierarchies (LINQ to SQL)
To implement inheritance mapping in LINQ, you must specify the attributes and attribute properties on the root class of the inheritance hierarchy as described in the following steps. Developers using Visual Studio can use the Object Relational Designer to map inheritance hierarchies. For more information, see How to: Configure Inheritance by Using the O/R Designer and How to: Configure Inheritance by Using the O/R Designer.
No special attributes or properties are required on the subclasses. Note especially that subclasses do not have the TableAttribute attribute.
To map an inheritance hierarchy
Add the TableAttribute attribute to the root class.
Also to the root class, add an InheritanceMappingAttribute attribute for each class in the hierarchy structure.
This property holds a value that appears in the database table in the IsDiscriminator column to indicate which class or subclass this row of data belongs to.
This property holds a value that specifies which class or subclass the key value signifies.
This property serves to designate a fallback mapping when the discriminator value from the database table does not match any Code value in the inheritance mappings.
This property signifies that this is the column that holds the Code value.
If you are using Visual Studio, you can use the Object Relational Designer to configure inheritance. For more information, see How to: Configure Inheritance by Using the O/R Designer and How to: Configure Inheritance by Using the O/R Designer.
In the following code example, Vehicle is defined as the root class, and the previous steps have been implemented to describe the hierarchy for LINQ. The following illustration shows the relationships.