I find it hard to understand why this code fails
I have a testing method
IUnitOfWork unitofwork = EFUnitOfWork.CreateInstance(); IRepository<InformationRequest> informationRequestRepository = unitofwork.CreateRepository<InformationRequest>(); IEnumerable<InformationRequest> requests = informationRequestRepository.ToList(); unitofwork.Dispose(); EFUnityOfWork.CreateInstance calls the EFUnitOfwork Constructor public EFUnitOfWork() { _currentContext = new MyDataContext(); }
Here is the code for CreateRepository
public IRepository<T> CreateRepository<T>() { return new Repository<T>(_currentContext); }
The test above does not work when testing a load. When I try to run it, it says: Fix System.Data.EntityException: the underlying provider refused to open. ---> System.InvalidOperationException: The connection was not closed. The status of the current connection is connected.
I get rid of the context and create a new one every time. I do not understand where I am mistaken.
source share