I am trying to achieve an abstraction in ASP.NET MVC with C#.
I have a base entity controller which should do most of the job for its derived classes(entities). In it, I have a problematic method which should return the database context of each table(I am not using any DB frameworks like EF). Here is the method:
protected abstract DbContext<EntityViewModel> CreateContext();
So, say I have a Category table, the method should be implemented:
protected override DbContext<EntityViewModel> CreateContext()
{
return new CategoryDbContext();
}
But C# says I can't implicitly cast it, etc...
Here are the context classes:
public abstract class DbContext<T>
{
public abstract void Create(T entity);
public abstract List<T> Read(ModifyData data);
public abstract void Update(T entity);
public abstract void Delete(T entity);
}
public class CategoryDbContext : DbContext<CategoryViewModel>
{
public override void Create(CategoryViewModel entity)
{
}
public override List<CategoryViewModel> Read(ModifyData data)
{
}
public override void Update(CategoryViewModel entity)
{
}
public override void Delete(CategoryViewModel entity)
{
}
}
What am I doing wrong here?