I am working on a base class for my entity framework database context classes. In the base class I need access to the DbContext and in the derived class I need access to the derived DbContext. At the moment I have the following code:
public abstract class BaseClass: IDisposable
{
protected abstract DbContext BaseContext { get; }
public void Dispose()
{
if (BaseContext != null)
{
BaseContext.Dispose();
}
}
}
public class DerivedClass : BaseClass
{
DerivedContext context; // public class DerivedContext: DbContext
protected override DbContext BaseContext
{
get
{
return context;
}
}
}
Is this a correct approach?
I would suggest something more like
In your base class you can access all of the member of DbContext and in your DerivedClass, you can access all of the members of DerviedContext without the need to cast.