LINQ DataContext and IDisposable
-
Hi - I'm implementing a data access layer in LINQ to SQL. I have a DataContext MyDataContext which extends DataContext. DataContext implements IDisposable. However when I try to put MyDataContext in a using statement I get a compiler error: 'MyDataContext':type used in a using statement must be implicitly convertible to 'System.IDisposable'. So is IDisposable not implicitly usable for derived classes or am I doing something wrong? Here is some sample code: using (MyDataContext context = new MyDataContext()) { //do some work }
-
Hi - I'm implementing a data access layer in LINQ to SQL. I have a DataContext MyDataContext which extends DataContext. DataContext implements IDisposable. However when I try to put MyDataContext in a using statement I get a compiler error: 'MyDataContext':type used in a using statement must be implicitly convertible to 'System.IDisposable'. So is IDisposable not implicitly usable for derived classes or am I doing something wrong? Here is some sample code: using (MyDataContext context = new MyDataContext()) { //do some work }
If your class inherits from DataContext, you get IDisposable for free. Could you post your class definition here so that we can take a look at it?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.