Database Reference
In-Depth Information
{
if (emp is HourlyEmployee)
Console.WriteLine("{0} Hours = {1}, Rate = {2}/hour",
emp.Name,
((HourlyEmployee)emp).Hours.Value.ToString(),
((HourlyEmployee)emp).Rate.Value.ToString("C"));
else if (emp is CommissionedEmployee)
Console.WriteLine("{0} Salary = {1}, Commission = {2}%",
emp.Name,
((CommissionedEmployee)emp).Salary.Value.ToString("C"),
((CommissionedEmployee)emp).Commission.ToString());
else if (emp is SalariedEmployee)
Console.WriteLine("{0} Salary = {1}", emp.Name,
((SalariedEmployee)emp).Salary.Value.ToString("C"));
}
}
The output of the code in Listing 6-25 is as follows:
All Employees
=============
Will Smith Hours = 39.00, Rate = $7.75/hour
JoAnn Woodland Salary = $65,400.00
Joel Clark Salary = $32,500.00, Commission = 20.00%
6-9. Applying Conditions in Table per Type Inheritance
Problem
You want to apply conditions while using Table per Type inheritance.
Solution
Let's say that you have the two tables depicted in Figure 6-11 . The Toy table describes toys a company produces.
Most toys manufactured by the company are for sale. Some toys are made just to donate to worthy charities. During
the manufacturing process, a toy may be damaged. Damaged toys are refurbished, and an inspector determines the
resulting quality of the refurbished toy.
Figure 6-11. Toy and RefurbishedToy tables with a one-to-one relationship
 
Search WWH ::




Custom Search