title: Using EntityFramework navigation properties when the DbContext is disposed
body: <p>The current retrieval pattern in my Service classes (in an ASP.NET MVC application) looks something like:</p>
  
  <pre><code>public Client Get(int id)
  {
      using (var repo = _repoFactory.Get&lt;Client&gt;())
      {
          return repo.Get(id);
      }
  }
  </code></pre>
  
  <p>Where <code>_repoFactory.Get&lt;T&gt;()</code> returns a repository which, when disposed, also disposes the Entity Framework <code>DbContext</code>;</p>
  
  <p>However, when the consumer of the <code>Get(int id)</code> method needs to use navigation properties on the <code>Client</code> object, an exception is thrown because the context is already disposed.</p>
  
  <p>I can foresee a few ways to negotiate this problem:</p>
  
  <ul>
  <li>Don't use navigation properties outside of the service</li>
  <li>Don't use lazy-loading navigation properties</li>
  <li>Find some other way to dispose of the context when the request is finished</li>
  </ul>
  
  <p>What is the "correct" (or least incorrect) way and how can it be accomplished?</p>