Database Reference
In-Depth Information
6-12. Modeling Table per Concrete Type Inheritance
Problem
You have two or more tables with similar schema and data, and you want to model these tables as types derived from
a common entity using Table per Concrete Type inheritance.
Solution
Let's assume that we have the tables shown in Figure 6-18 .
Figure 6-18. Tables Toyota and BMW with similar structure that will become derived types of the Car entity
In Figure 6-18 , the tables Toyota and BMW have similar schema and represent similar data. The BMW table has
an additional column with a bit value indicating whether the instance has the collision-avoidance feature. We want
to create a model with a base entity holding the common properties of the Toyota and BMW tables. Additionally, we
want to represent the one-to-many relationship between the car dealer and cars held in inventory. Figure 6-22 shows
the final model.
To create the model, do the following:
1.
Add a new ADO.NET Entity Data Model to your project, and import the Toyota, BMW,
CarDealer, and Dealer tables.
2.
Right-click the design surface, and select Add Entity. Name the new entity Car, and
unselect the Create key property check box.
Right-click the Car entity, and view its properties. Set the Abstract property to true .
3.
4.
Move the common properties of the Toyota and BMW entities to the Car entity. You can
use Cut/Paste to move these properties. Make sure that only the CollisionAvoidance
property remains with the BMW entity and the Toyota entity has no properties. Both of
these entities will inherit these common properties from the Car entity.
5.
Right-click the Car entity, and select Add Inheritance. Set the base entity as Car and the
derived entity as BMW.
 
Search WWH ::




Custom Search