Database Reference
In-Depth Information
if (person is Firefighter)
Console.WriteLine("Firefighter at station {0}",
((Firefighter)person).FireStation);
else if (person is Teacher)
Console.WriteLine("Teacher at {0}", ((Teacher)person).School);
else if (person is Retired)
Console.WriteLine("Retired, hobby is {0}",
((Retired)person).FullTimeHobby);
Console.WriteLine("Fans:");
foreach (var fan in person.Fans)
{
Console.WriteLine("\t{0}", fan.Name);
}
}
}
The output from the code in Listing 6-11 is as follows:
Susan Smith, Hero is: Joan Collins
Teacher at Custer Baker Middle School
Fans:
Joel Clark
Joel Clark, Hero is: Susan Smith
Firefighter at station Midtown
Fans:
Joan Collins
Joan Collins, Hero is: Joel Clark
Retired, hobby is Scapbooking
Fans:
Susan Smith
6-5. Modeling a Self-Referencing Relationship and Retrieving
a Complete Hierarchy
Problem
You are using a self-referencing table to store hierarchical data. Given a record, you want to retrieve all associated
records that are part of that hierarchy at any level deep.
Solution
Suppose that you have a Category table like the one in the database diagram shown in Figure 6-6 .
 
 
Search WWH ::




Custom Search