Database Reference
In-Depth Information
context.People.Add(new Student { Name = "Jill Mathers",
Degree = "Computer Science" });
context.People.Add(new Student { Name = "Steven Kennedy",
Degree = "Math" });
context.SaveChanges();
}
using (var context = new EF6RecipesContext())
{
Console.WriteLine("Instructors and Students");
var allPeople = context.GetAllPeople();
foreach (var person in allPeople)
{
if (person is Instructor)
Console.WriteLine("Instructor {0} makes {1}/year",
person.Name,
((Instructor)person).Salary.ToString("C"));
else if (person is Student)
Console.WriteLine("Student {0}'s major is {1}",
person.Name, ((Student)person).Degree);
}
}
The following is the output of the code in Listing 10-20:
Instructors and Students
Instructor Karen Stanford makes $62,500.00/year
Instructor Robert Morris makes $61,800.00/year
Student Jill Mathers's major is Computer Science
Student Steven Kennedy's major is Math
How It Works
Using a stored procedure to populate entities in a Table per Hierarchy inheritance model turns out to be a little easier
than for Table per Type (see Recipe 10-6). Here the stored procedure just selected all rows in the Person table. The
PersonType column contains the discriminator value that we use in <FunctionImportMapping> in Listing 10-19 to
map the rows conditionally either to the Student or to the Instructor entity. In Recipe 10-6, the stored procedure
had to create the column. In this recipe as well as in Recipe 10-6, the key part is the conditional mapping in the
<FunctionImportMapping> tag.
10-8. Mapping the Insert, Update, and Delete Actions to Stored
Procedures
Problem
You want to map the Insert, Update, and Delete actions to stored procedures.
 
Search WWH ::




Custom Search