Wednesday 20 February 2013

How to fix error: The operation cannot be completed because the DbContext has been disposed.


Watch online:



Replace

        public IQueryable getGroups()
        {
            using (CompanyTestEntities db = new CompanyTestEntities())
            {
                var result = db.GroupMasters;
                return result;
            }
        }
With

        public List<GroupMaster> getGroups()
        {
            using (CompanyTestEntities db = new CompanyTestEntities())
            {
                var result = db.GroupMasters.ToList();
                return result;
            }
        }

No comments:

Post a Comment