title: ObjectDisposedException occuring when getting list from database
body: <p>Using ASP.NET MVC 5 with Entity Framework 6, I am trying to get a list of all the notifications values a user has from the database. This code did work at one point and now I get an <code>ObjectDisposedException</code> when trying to send the list back to the javascript.</p>
  
  <p>Controller method:</p>
  
  <pre><code>public JsonResult NotifPrefsOpen()
  {
          try
          {
              List&lt;NotificationPreference&gt; notifPreference;
  
              using (MEDContext MContext = new MEDContext())
              using (StaffContext SContext = new StaffContext())
              {
                  AuthorizationUtil au = new AuthorizationUtil(HttpContext, MContext, SContext);
                  PreferenceService ps = new PreferenceService(MContext);
                  notifPreference = ps.NotificationAllGet(au.EmployeeNumber);
  
                  return Json(new { Success = true , notifPreference});
              }
          }
          catch (Exception ex)
          {
              Response.StatusCode = (int)HttpStatusCode.InternalServerError;
              string msg = LogError(GetType().FullName, ex);
              return Json(new { Success = false, ErrorMessage = msg });
          }
  }
  </code></pre>
  
  <p>Service Method</p>
  
  <pre><code>public List&lt;NotificationPreference&gt; NotificationAllGet (int employeeNumber)
  {
      IQueryable&lt;NotificationPreference&gt; result = 
             (from n in _context.NotificationPreference
              where n.employeeNumber == employeeNumber
              select n);
      return result.ToList();
  }
  </code></pre>
  
  <p>Here is the exception:</p>
  
  <blockquote>
    <p>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. </p>
    
    <p>System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.</p>
    
    <p>at System.Data.Entity.Core.Objects.ObjectContext.get_Connection()<br>
    at System.Data.Entity.Core.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1 forMergeOption)<br>
    at System.Data.Entity.Core.Objects.ObjectQuery<code>1.Execute(MergeOption mergeOption)<br>
    at System.Data.Entity.Core.Objects.DataClasses.EntityReference</code>1.Load(MergeOption  mergeOption)<br>
    at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad()<br>
    at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)<br>
    at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.&lt;>c__DisplayClass7`2.b__2(TProxy proxy, TItem item)<br>
    at System.Data.Entity.DynamicProxies.NotificationPreferen_93CF7ED7D23D42FE98298039206E4A93E5B136BB3DCBF9EFA5D02A3E8330CADF.get_AppUser()  </p>
  </blockquote>