title: Should DBContext be globally defined or explicitly created every time?
body: <p>I'm a SQL guy who's tinkering with Web API and Entity Framework 6 and I keep receiving the error "The operation cannot be completed because the DbContext has been disposed" when I my code is:</p>
  
  <pre><code>        namespace DataAccessLayer.Controllers
          {
             public class CommonController : ApiController
               {
                 [Route("CorrespondenceTypes")]
                 [HttpGet]
                 public IQueryable GetCorrespondenceTypes()
                 {
                      using (var coreDB = new coreEntities())
                      {
                          var correspondenceType = coreDB.tblCorrespondenceTypes.Select(cor =&gt; new { cor.CorrespondenceTypeName });
                          return correspondenceType;
                      }
                 }
               }
          }
  </code></pre>
  
  <p>But if change my code around a little and try this it works:</p>
  
  <pre><code>    namespace DataAccessLayer.Controllers
      {
          public class CommonController : ApiController
          {
              readonly coreEntities coreDB = new coreEntities();
  
              [Route("CorrespondenceTypes")]
              [HttpGet]
              public IQueryable GetCorrespondenceTypes()
              {
                      var correspondenceType = coreDB.tblCorrespondenceTypes.Select(cor =&gt; new { cor.CorrespondenceTypeName });
                      return correspondenceType;
              }
          }
      }
  </code></pre>
  
  <p>My question is why does the second one work but not the first?  Is it better practice to have a global connection string or call DBContext explicitly each time? </p>