Database Reference
In-Depth Information
Solution
Let's say that your database contains the tables shown in the database diagram in Figure 6-8 .
Figure 6-8. A database diagram containing Staff, Principal, and Instructor tables
In Figure 6-8 , we have a Staff table containing the name of the staff member and two related tables containing
information about Principals and Instructors. The important thing to notice here is that the Principal and Instructor
tables have primary keys that are not the foreign keys for the Staff table. This type of relationship structure is not
directly supported in Table per Type inheritance. For Table per Type, the related tables' primary keys must also be
the foreign key for the primary (base) table. Also notice that the relationship is one-to-one. This is because we have
constrained the StaffId columns in the Principal and Instructor tables to be unique by creating a unique index on this
column in both tables.
To model the tables and relationships in Figure 6-8 using Table per Type inheritance, do the following:
1.
Add a new ADO.NET Entity Data Model to your project, and import the Staff, Principal,
and Instructor tables.
2.
Delete the associations between the Principal and the Staff entities and between the
Instructor and the Staff entities.
3.
Right-click the Staff entity, and choose Add Inheritance. Select Staff as the base entity
and Principal as the derived entity. Repeat this step by selecting Staff as the base entity and
Instructor as the derived entity.
4.
Delete the StaffId property from the Instructor and Principal entities.
5.
Right-click the Staff entity, and choose Properties. Set the Abstract attribute to True. This
marks the Staff entity as abstract.
6.
Because the StaffId is not the primary key in either the Principal or the Instructor tables,
we cannot use the default table mapping to map the Principal, Instructor, or Staff entities.
Select each entity, view the Mapping Details window, and delete the table mapping.
Repeat this for each entity.
 
Search WWH ::




Custom Search