Skip to content

Instantly share code, notes, and snippets.

@mikecole
Last active December 23, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecole/6641186 to your computer and use it in GitHub Desktop.
Save mikecole/6641186 to your computer and use it in GitHub Desktop.
Eager Loading - More Examples
var posts = context.Posts
.Include(p => p.Author.JobTitle) //We are going two levels deep
.ToArray();
//We are going two levels deep here, also. However, since Authors.Posts is a collection, we
//need to do a little LINQ-Fu to properly include Categories.
var author = context.Authors
.Include(a => a.Posts.Select(p => p.Category))
.Single(a => a.ID == id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment