public void SaveChanges() { assertNotDisposed(); processChangeTrackers(); if (!_unitOfWork.HasOutstandingWork()) { return; } Database.BeginTransaction(); applyProjections(); _unitOfWork.Sort(Options); foreach (var listener in Listeners) { listener.BeforeSaveChanges(this); } var batch = new UpdateBatch(_unitOfWork.AllOperations); try { batch.ApplyChanges(this); Database.Commit(); } catch (Exception) { Database.Rollback(); throw; } resetDirtyChecking(_unitOfWork); EjectPatchedTypes(_unitOfWork); Logger.RecordSavedChanges(this, _unitOfWork); foreach (var listener in Listeners) { listener.AfterCommit(this, _unitOfWork); } // Need to clear the unit of work here _unitOfWork = new UnitOfWork(this); }
public void SaveChanges() { assertNotDisposed(); processChangeTrackers(); if (!_unitOfWork.HasOutstandingWork()) { return; } Database.BeginTransaction(); Options.Events.ProcessEvents(this); _unitOfWork.Sort(Options); foreach (var listener in Listeners) { listener.BeforeSaveChanges(this); } var batch = new UpdateBatch(_unitOfWork.AllOperations); try { batch.ApplyChanges(this); Database.Commit(); } catch (Exception) { Database.Rollback(); if (Options.Events.TryCreateTombstoneBatch(this, out var tombstoneBatch)) { try { tombstoneBatch.ApplyChanges(this); } catch (Exception) { // Failures are logged within the ManagedConnection } } throw; } resetDirtyChecking(); EjectPatchedTypes(_unitOfWork); Logger.RecordSavedChanges(this, _unitOfWork); foreach (var listener in Listeners) { listener.AfterCommit(this, _unitOfWork); } // Need to clear the unit of work here _unitOfWork = new UnitOfWork(this); }