Database Reference
In-Depth Information
2-10. Modeling Table per Hierarchy Inheritance
Problem
You have a table with a type or discriminator column that you use to determine what the data in a row represents in
your application. You want to model this with table per hierarchy inheritance.
Solution
Let's say that your table looks like the one shown in Figure 2-20 . This Employee table contains rows for both hourly
employees and salaried employees. The EmployeeType column is used to discriminate between the two types of rows.
When EmployeeType is 1, the row represents a salaried or full-time employee. When the EmployeeType is 2, the row
represents an hourly employee.
Figure 2-20. An Employee table containing both hourly and full-time employees
To create a model using table per hierarchy inheritance based on the Employee table, do the following:
1.
Create a new class in your project that inherits from DbContext.
Create an abstract Employee POCO entity class using the code in Listing 2-21.
2.
 
Search WWH ::




Custom Search