Database Reference
In-Depth Information
using (var context = new EFRecipesEntities())
{
var resume = context.Resumes.Single();
Console.WriteLine("Title: {0}, Name: {1}", resume.Title, resume.Name);
// note, the ResumeDetail is not loaded until we reference it
Console.WriteLine("Body: {0}", resume.ResumeDetail.Body);
}
Following is the output of the code in Listing 13-22:
Title: C# Developer, Name: Sally Jones
Body: ...very long resume goes here...
How It Works
We avoided loading the expensive Body property on the Resume entity by moving the property to a new related entity.
By splitting the underlying table across these two entities, we can exploit the default lazy loading of Entity Framework
so that the Body property is loaded only when we reference it. This is a fairly clean approach to the problem, but it
does introduce an additional entity into our model that we have to manage in our code.
the following link shows how to move a property from one entity to another entity using the Code-first
approach: http://msdn.microsoft.com/en-us/data/jj591617#2.8 . this process is referred to as Entity Splitting ,
allowing the properties of an entity type to be spread across multiple tables.
Note
13-9. Avoiding Include
Problem
You want to eagerly load a related collection without using Include() . Additionally, you want to implement the Entity
Framework Code-First approach.
Solution
Let's say that you have a model like the one shown in Figure 13-14 .
 
 
Search WWH ::




Custom Search