forum

Home / DeveloperSection / Forums / How to dispose the context variable in c#?

How to dispose the context variable in c#?

Anonymous User 2541 22-Jan-2014

I want to dispose the devDB context object in the below code.

private static void InitContainer()
{
     var devDB = new TestContext(constr); 
                 Container                
                    .RegisterInstance<TestContext>(devDB)
                    .RegisterInstance<IRepository<User>>(new Repository<User>(devDB))
}
private static void CleanUp()
{
    if (Container != null)
    {
        Container.Dispose();
    }
}

I tried a using statement, but the I receive the following error:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

How can I dispose devDB correctly?


c# c# 
Updated on 23-Jan-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By