Database Reference
In-Depth Information
foreach (var detail in order.OrderDetails)
{
Console.WriteLine(
"\t{0}, {1} units at {2} each, unit discount: {3}",
detail.Product.ProductName,
detail.Quantity.ToString(),
detail.UnitPrice.ToString("C"),
(detail.Product.UnitPrice - detail.UnitPrice).ToString("C"));
}
}
}
}
The following is the output of the code in Listing 8-3:
Orders for Karen Marlowe
--Order Date: 4/19/2010--
Green Tea, 4 units at $1.00 each, unit discount: $0.09
Colombian Coffee, 3 units at $2.15 each, unit discount: $0.00
How It Works
The POCO class generation is the default feature of current version of Entity Framework. Code generation property
value is already set to None. The DbContext class is also generated separately, so no data access code is plugged into
the POCO classes.
All of the classes corresponding to each of the entities in our model are created. They are pretty simple and clean.
Of course, without code generation, no DbContext is generated. To implement a DbContext that is specific to our
model and our entities, a new class derived from DbContext is created while generating the Entity Data Model, and
this class provides properties of type DbSet<T> corresponding to each of the Db sets in our context. By default, our
EFRecipesEntities DbContext has the constructor code that enables it to be connected to the underlying database.
8-2. Loading Related Entities with POCO
Problem
Using POCO, you want to eagerly load related entities.
Solution
Suppose that you have a model like the one in Figure 8-3 .
 
 
Search WWH ::




Custom Search