I have an implementation of Entity Framework Core's DbContext
class, MyTestDbContext
.
Now I don't want other developers to call MyTestDbContext.SaveChanges()
because I would like them to call an overload of it I created, MyTestDbContext.SaveChanges(string userName)
.
In case they call the MyTestDbContext.SaveChanges()
method, I have overridden it to throw an exception, but how can I call the base.SaveChanges()
from my new SaveChanges(string userName)
method?
This code, when executing return base.SaveChanges()
, calls the child method and throws the exception.
How can I avoid this and directly call its parent?
public class MyTestDbContext: DbContext {
public override int SaveChanges()
{
throw new Exception("Use SaveChanges(userName) instead");
}
public int SaveChanges(string userName)
{
if (userName == "admin")
return base.SaveChanges();
else return 1;
}
}