Properly disposing of my Entity Framework entity

curiouswebster
curiouswebster used Ask the Experts™
on
I created a data repository that contains an instance of my Entity Framework entity.  And I want to use a "using" statement to manage it's immediate disposal.  So I implement IDisposable and created the following Dispose() function.

        public MyDataStore()
        {
            entities = new MyEF4object();
        }

        public void Dispose()
        {
            entities.Dispose();
            entities = null;
        }

is this right?  I want to terminate and garbage collect the database connection upon exit from the function where this object is created and used.

Will I create problems setting it to null?  

thanks,newbieweb
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You only need to dispose of objects that contain unmanaged resources. If your objects are plain vanilla .net objects, there's no need to implement IDisposable. It won't buy you anything.
curiouswebsterSoftware Engineer

Author

Commented:
If I have a database connection to worry about terminating, I need to use IDisposable.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial