title: Using Entity Framework navigation properties without creating lots of queries (avoiding N+1)
body: <p>I've been using Entity Framework Profiler to test my data access in an MVC project and have come accross several pages where I'm making far more db queries than I need to because of N+1 problems.</p>
  
  <p>Here is a simple example to show my problem:</p>
  
  <pre><code>var club = this.ActiveClub; // ActiveClub uses code similar to context.Clubs.First() 
  var members = club.Members.ToList();
  return View("MembersWithAddress", members);
  </code></pre>
  
  <p>The view loops through Members and then follows a navigion property on each member to also show their address. Each of the address requests results in an extra db query.</p>
  
  <p>One way to solve this would be to use Include to make sure the extra tables I need are queried up front. However, I only seem to be able to do this on the ObjectSet of Clubs attached directly to the context. In this case the ActiveClub property is shared by lots of controllers and I don't always want to query the Member and address table up front.</p>
  
  <p>I'd like to be able to use something like:</p>
  
  <pre><code>var members = club.Members.Include("Address").ToList();
  </code></pre>
  
  <p>But, Members is an EntityCollection and that doesn't have the Include method on it.</p>
  
  <p>Is there a way to force a load on the Members EntityCollection and ask EF to also load their Addresses?</p>
  
  <p>Or, is using EntityCollection navigation properties on an entity in this way, just a really bad idea; and you should know what you're loading when you get it from the context?</p>