Database Reference
In-Depth Information
using (var context = new EF6RecipesContext())
{
context.ContextOptions.LazyLoadingEnabled = true;
Console.WriteLine("-- All Locations -- ");
foreach (var l in context.Locations)
{
Console.WriteLine("{0}, {1}, {2} {3}", l.Address, l.City,
l.State, l.ZIPCode);
}
Console.WriteLine("--- Parks ---");
foreach (var p in context.Locations.OfType<Park>())
{
Console.WriteLine("{0} is at {1} in {2}", p.Name, p.Address, p.City);
Console.WriteLine("\tOffice: {0}, {1}, {2} {3}", p.Office.Address,
p.Office.City, p.Office.State, p.Office.ZIPCode);
}
}
The output of the code in Listing 2-26 is as follows:
-- All Locations --
501 Main, Weatherford, TX 76201
801 11th Street, Aledo, TX 76106
8705 Range Lane, Springtown, TX 76081
101 High Drive, Springtown, TX 76081
--- Parks ---
11th Street Park is at 801 11th Street in Aledo
Office: 501 Main, Weatherford, TX 76201
Overland Park is at 101 High Drive in Springtown
Office: 8705 Range Lane, Springtown, TX 76081
2-12. Creating, Modifying, and Mapping Complex Types
Problem
You want to create a complex type, set it as a property on an entity, and map the property to some columns on a table.
Solution
Let's say that you have the table shown in Figure 2-23 . You want to create a Name complex type for the FirstName and
LastName columns. You also want to create an Address complex type for the AddressLine1, AddressLine2, City, State,
and ZIPCode columns. You want to use these complex types for properties in your model, as shown in Figure 2-24 .
 
 
Search WWH ::




Custom Search