Deep understanding of lazy loading and disposing error in MVC .net
i was trying to write a full detailed answer to the following question: Why does "Dispose" work, and not "using(var db = new DataContext())"? so I set up my project that include: Departments and employees using entity framework so my action method was this: public ActionResult Index() { IEnumerable<department> d; using (var ctx = new ApplicationDbContext()) { d = ctx.departments; } return View(d); } it is natural to expect that this will result in the common error : The operation cannot be completed because the DbContext has been disposed and when i wanted to resolve it I did the following [to