public async Task SaveChangesAsync(CancellationToken token) { if (!_unitOfWork.HasAnyUpdates()) { return; } assertNotDisposed(); await _connection.BeginTransactionAsync(token).ConfigureAwait(false); await applyProjectionsAsync(token).ConfigureAwait(false); foreach (var listener in Listeners) { await listener.BeforeSaveChangesAsync(this, token).ConfigureAwait(false); } var batch = new UpdateBatch(_store, _connection, IdentityMap.Versions, WriterPool, Tenant, Concurrency); var changes = await _unitOfWork.ApplyChangesAsync(batch, token).ConfigureAwait(false); EjectPatchedTypes(changes); try { await _connection.CommitAsync(token).ConfigureAwait(false); IdentityMap.ClearChanges(); } catch (Exception) { // This code has a try/catch in it to stop // any errors from propogating from the rollback await _connection.RollbackAsync(token).ConfigureAwait(false); throw; } Logger.RecordSavedChanges(this, changes); foreach (var listener in Listeners) { await listener.AfterCommitAsync(this, changes, token).ConfigureAwait(false); } }
public void SaveChanges() { if (!_unitOfWork.HasAnyUpdates()) { return; } assertNotDisposed(); _connection.BeginTransaction(); applyProjections(); foreach (var listener in Listeners) { listener.BeforeSaveChanges(this); } var batch = new UpdateBatch(_store, _connection, IdentityMap.Versions, WriterPool, Tenant, Concurrency); var changes = _unitOfWork.ApplyChanges(batch); EjectPatchedTypes(changes); try { _connection.Commit(); IdentityMap.ClearChanges(); } catch (Exception) { // This code has a try/catch in it to stop // any errors from propogating from the rollback _connection.Rollback(); throw; } Logger.RecordSavedChanges(this, changes); foreach (var listener in Listeners) { listener.AfterCommit(this, changes); } }
public void SaveChanges() { if (!_unitOfWork.HasAnyUpdates()) { return; } assertNotDisposed(); _connection.BeginTransaction(); applyProjections(); _sessionListeners.Each(x => x.BeforeSaveChanges(this)); var batch = new UpdateBatch(_options, _serializer, _connection, IdentityMap.Versions, WriterPool); var changes = _unitOfWork.ApplyChanges(batch); try { _connection.Commit(); IdentityMap.ClearChanges(); } catch (Exception) { // This code has a try/catch in it to stop // any errors from propogating from the rollback _connection.Rollback(); throw; } Logger.RecordSavedChanges(this, changes); _sessionListeners.Each(x => x.AfterCommit(this, changes)); }