public void Delete(TEntity entity) { if (EFContext.Entry <TEntity>(entity).State == EntityState.Detached) { EFSet.Attach(entity); } EFSet.Remove(entity); }
public void DeleteRange(IEnumerable <TEntity> entities, int batchSize = 100, bool autoCommitEnabled = false) { try { if (entities == null) { throw new ArgumentNullException("entities"); } if (entities.HasItems()) { if (batchSize <= 0) { // insert all in one step entities.Each(x => EFSet.Add(x)); } else { int i = 1; bool saved = false; foreach (var entity in entities) { EFSet.Remove(entity); saved = false; if (i % batchSize == 0) { i = 0; saved = true; } i++; } } } } catch (DbEntityValidationException ex) { throw ex; } }