Database Reference
In-Depth Information
The stored procedure in Listing 10-15 forms a union of rows from the Magazine and DVD tables, and it injects the
strings Magazine or DVD into the MediaType discriminator column. For each select, we join to the Media table, which
is represented in the model by the base entity, to include the Title column. All of the rows from all three tables are now
in the result set with each row tagged to indicate the table from where it came.
With each row tagged with either Magazine or DVD, we conditionally map the rows either to the Magazine or
DVD entities based on the tag or value in the discriminator column. This is done in the <FunctionImportMapping>
section.
In Listing 10-17, we call the CLR method GetAllMedia() , which we mapped to the GetAllMedia stored
procedure when we added the Function Import. When we call GetAllMedia() , the entire object graph is
materialized with the inheritance hierarchy intact. We iterate through the collection, alternately printing out the
Magazine and DVD entities.
10-7. Populating Entities in a Table per Hierarchy
Inheritance Model
Problem
You want to use a stored procedure to populate entities in a Table per Hierarchy inheritance model.
Solution
Suppose you have a model like the one shown in Figure 10-7 . We have two derived entities: Instructor and Student.
Because this model is using Table per Hierarchy inheritance, we have just one table in the database. The Person table
has a discriminator column that is used to map the table to the derived entities. You want to populate the entities with
a stored procedure.
Figure 10-7. A model for instructors and students
 
Search WWH ::




Custom Search