CequeNugninia
New Member
My page calls a Services layer method that uses a Generic Repository "Find" method. In the services layer method, I do the following:\[code\] using (IUnitOfWork unitOfWork = new DBContext()) { GenericRepository<Operator> operatorRepos = new GenericRepository<Operator>(unitOfWork); { try { var oper = operatorRepos.Find(o => peratorID == operatorID).Include(o => o.cmn_Address).Single(); return oper; } catch (InvalidOperationException exc) { //handle exception } } }\[/code\]The Find method for my repository:\[code\]public IQueryable<T> Find(Func<T, bool> predicate) { return _objectSet.Where<T>(predicate).AsQueryable(); }\[/code\]On the page, I try to access the cmn_address Navigation property of the Operator and I get the following error:The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.I realize that this is caused by the using statement to dispose of the context, but I thought the Include method will eager load the cmn_Address object. I don't understand why this doesn't work as I expected.