public void Update(T item) { try { using (context) { var entity = context.Set <T>().Where(t => t.Id == item.Id).FirstOrDefault(); if (entity != null) { context.Entry(entity).CurrentValues.SetValues(item); context.SaveChanges(); } } } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += Environment.NewLine + $"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}"; } } var fail = new Exception(msg, dbEx); throw fail; } }
public void Update(T item) { try { using (context) { var entity = context.Set <T>().FirstOrDefault(t => t.Id == item.Id); if (entity != null) { context.Entry(entity).CurrentValues.SetValues(item); context.SaveChanges(); } } } catch (DbEntityValidationException dbEx) { throw dbEx; } }