public void Delete(T entity) { try { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Entities.Remove(entity); _context.SaveChanges(); } catch (DbEntityValidationException dbEx) { var msg = dbEx.EntityValidationErrors.Aggregate(string.Empty, (current1, validationErrors) => validationErrors.ValidationErrors.Aggregate(current1, (current, validationError) => current + (Environment.NewLine + $"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}"))); var fail = new Exception(msg, dbEx); throw fail; } }
public void Commit() { _dbContext.ChangeTracker.DetectChanges(); _dbContext.SaveChanges(); }