Database Reference
In-Depth Information
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Competitor> Competitors { get; set; }
public DbSet<Event> Events { get; set; }
public DbSet<Venue> Venues { get; set; }
}
The following is the output of the code in Listing 8-4:
Venue: City Center Hall
Event: All Star Boxing
--- Competitors ---
Big Joe Green
Terminator Tim
Venue: Sports and Recreational Grounds
Event: Inter-school Soccer
--- Competitors ---
St. Mary's School
City School
How It Works
When we're using code generated by Entity Framework for our model, we use the Include() method on the context
query objects to load the related entities, and these related entities can be lists of entities or single objects. There are
three methods of loading or querying related entities in Entity Framework: Eager Loading, Lazy Loading, and Explicit
Loading. We have used the Include() method to demonstrate eagerly loading related entities. By default, Lazy
Loading is enabled in Entity Framework, but we have disabled that here. To load a navigation property explicitly when
using POCO, you need to use the Include() method exposed on the DbContext.
8-3. Lazy Loading with POCO
Problem
You are using Plain Old CLR Objects, and you want to lazy load related entities.
Solution
Let's say that you have a model like the one in Figure 8-4 .
 
 
Search WWH ::




Custom Search