public int SaveChanges() { int affectedRow = 0; try { if (_context == null) { throw new ArgumentNullException("_context"); } affectedRow = _context.SaveChanges(); } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine; } } var fail = new Exception(msg, dbEx); throw fail; } return(affectedRow); }