public int Add(T t) { context.Set <T>().Add(t); context.Set <T>().Distinct(); try { return(context.SaveChanges()); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { var cls = validationErrors.Entry.Entity.GetType().FullName; var prop = validationError.PropertyName; var errmsg = validationError.ErrorMessage; Trace.TraceInformation("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName, validationError.PropertyName, validationError.ErrorMessage); } } throw; } //return null; }
public void SaveChanges() { try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { var cls = validationErrors.Entry.Entity.GetType().FullName; var prop = validationError.PropertyName; var errmsg = validationError.ErrorMessage; Trace.TraceInformation("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName, validationError.PropertyName, validationError.ErrorMessage); } } throw; } }