Eager load additional data about some instructors
The query to the database wont't be executed by writing this linq statement  


var viewModel = new InstructorIndexData
{
    Instructors = _db.Instructors
        .Include(i =&gt; i.OfficeAssignment)
        .Include(i =&gt; i.Courses.Select(c =&gt; c.Department))
        .OrderBy(i =&gt; i.LastName)
};  



if the InstructorIndexData.Instructors property setter isn't executing any of the following actions  


enumerating the elements by a for..each loop  
calling ToArray(), ToDictionary() or ToList() on the IEnumerable  
calling a linq operator like First(), Any  


See: https://msdn.microsoft.com/en-us/data/jj573936.aspx  

So, if you call ToList() on the enumerable shown above, only one call to the database will be made.  

 var viewModel = new InstructorIndexData
 {
     Instructors = _db.Instructors
         .Include(i =&gt; i.OfficeAssignment)
         .Include(i =&gt; i.Courses.Select(c =&gt; c.Department))
         .OrderBy(i =&gt; i.LastName)
         .ToList()
 };  


The call to  


viewModel.Courses = viewModel.Instructors.Single(i =&gt; i.InstructorId == id.Value).Courses;  



will then operate on the retrieved data and won't need a trip to the database anymore.