Database Reference
In-Depth Information
context.Staffs.Add(principal);
context.Staffs.Add(instructor);
context.SaveChanges();
}
using (var context = new EF6RecipesContext())
{
Console.WriteLine("Principals");
Console.WriteLine("==========");
foreach (var p in context.Staffs.OfType<Principal>())
{
Console.WriteLine("\t{0}, Salary: {1}, Bonus: {2}",
p.Name, p.Salary.ToString("C"),
p.Bonus.ToString("C"));
}
Console.WriteLine("Instructors");
Console.WriteLine("===========");
foreach (var i in context.Staffs.OfType<Instructor>())
{
Console.WriteLine("\t{0}, Salary: {1}", i.Name, i.Salary.ToString("C"));
}
}
The following is the output of the code in Listing 6-22:
Principals
==========
Robbie Smith, Salary: $48,000.00, Bonus: $3,500.00
Instructors
===========
Joan Carlson, Salary: $39,000.00
6-8. Modeling Nested Table per Hierarchy Inheritance
Problem
You want to model a table using more than one level of Table per Hierarchy inheritance.
Solution
Suppose that we have an Employee table that contains various types of employees such as Hourly and Salaried
Employee, as shown in Figure 6-10 .
 
 
Search WWH ::




Custom Search