Database Reference
In-Depth Information
On the query side, we retrieve each of the photographs from the database, print some information about the
photograph, and then explicitly load the associated PhotographFullImage entity. Notice that we did not change the
default context option to turn off lazy loading. This puts the burden on us to load related entities explicitly. This is
just what we want. We could have chosen not to load the associated instances of PhotographFullImage , and if we
were iterating through hundreds or thousands of photographs, this would have saved us an awful lot of cycles and
bandwidth.
2-8. Modeling Table per Type Inheritance
Problem
You have some tables that contain additional information about a common table, and you want to model this using
table per type inheritance.
Solution
Suppose that you have two tables that are closely related to a common table, as shown in Figure 2-17 . The Business
table is on the 1 side of a 1:0..1 relationship with the eCommerce and the Retail tables. The key feature here is that the
eCommerce and Retail tables extend information about a business represented in the Business table.
Figure 2-17. Closely related tables ripe for inheritance
The tables Retail and eCommerce are related to the Business table, which holds a few properties that we would
naturally associate with any business. To model table per type inheritance such that entities Retail and eCommerce
inherit from the Business base entity type, perform the following steps:
1.
Create a new class in your project that inherits from DbContext.
Create a Business POCO entity class using the code in Listing 2-16.
2.
 
Search WWH ::




Custom Search