With EF, any data value in Entity instance can be saved back to database by calling SaveChanges which can be overridden to add custom action.
So I try to override SaveChanges in following way:
public override int SaveChanges(System.Data.Objects.SaveOptions options)
{
try
{
return base.SaveChanges(options);
}
catch (Exception ex)
{
//error log here
//write the error message to database table errorlog
throw ex;
}
}
when SaveChange failed, I want to grab the exception and save the error message to a table in same database. With about code, even save data to table errorlog, also should call SaveChanges. How to resolve this problem?