Database Reference
In-Depth Information
Figure 8-4. A simple model for traffic tickets, the offending vehicles, and the details of the violation
To enable lazy loading, you don't need to do anything. Lazy loading is enabled by default when an Entity Data
Model is added into a Visual Studio project. The code in Listing 8-5 illustrates this approach.
Listing 8-5. Entity Classes Generation and Properties Set to Virtual: A Default Behavior of Entity Framework
class Program
{
static void Main(string[] args)
{
RunExample();
}
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
var vh1 = new Vehicle { LicenseNo = "BR-549" };
var t1 = new Ticket { IssueDate = DateTime.Parse("06/10/13") };
var v1 = new Violation
{
Description = "20 MPH over the speed limit",
Amount = 125M
};
var v2 = new Violation
{
Description = "Broken tail light",
Amount = 50M
};
t1.Violations.Add(v1);
t1.Violations.Add(v2);
t1.Vehicle = vh1;
context.Tickets.Add(t1);
var vh2 = new Vehicle { LicenseNo = "XJY-902" };
var t2 = new Ticket { IssueDate = DateTime.Parse("06/12/13") };
var v3 = new Violation
 
Search WWH ::




Custom Search