Database Reference
In-Depth Information
The application that generates reports for the company has no need to access toys manufactured for donations.
To create a model that filters out toys manufactured for donation while representing the Toy and RefurbishedToy
tables using Table per Type inheritance, do the following:
1.
Add a new ADO.NET Entity Data Model to your project, and import the Order and
Lookup tables.
2.
Delete the association between Toy and RefurbishedToy.
3.
Right-click the Toy entity, and select Add Inheritance. Select Toy as the base entity and
RefurbishedToy as the derived entity.
4.
Delete the ToyId property in the RefurbishedToy entity.
5.
Select the RefurbishedToy entity. In the Mapping Details window, map the ToyId column
to the ToyId property. This value will come from the Toy base entity.
6.
Delete the ForDonationOnly scalar property from the Toy entity.
7. Select the Toy entity, and view the Mapping Details window. Use Add a Table or View to
map this entity to the Toy table. Add a condition When ForDonationOnly = 0 .
The resulting model is shown in Figure 6-12 .
Figure 6-12. The completed model with the Toy entity and derived RefurbishedToy entity
How It Works
We limited the RefurbishedToy instances to nondonation toys by applying a condition on the base entity. This
approach is useful in cases such as when we need to apply a permanent filter to an inheritance structure while using
separate tables to implement some of the derived types.
The code in Listing 6-26 demonstrates inserting into and retrieving from our model.
 
Search WWH ::




Custom Search