/// <summary> /// 提交事务 /// </summary> public void Commit() { if (!isRealTransaction) { return; } BeforeCommit?.Invoke(); Transaction?.Commit(); AfterCommit?.Invoke(); }
public Task <int> CommitAsync() { BeforeCommit?.Invoke(this, new BeforeCommit()); return(uow.CommitAsync() .ContinueWith(task => { int?changes = task.Status == TaskStatus.RanToCompletion ? new int?(task.Result) : null; Exception ex = task.Exception; AfterCommit?.Invoke(this, new AfterCommit(changes, ex)); if (ex != null) { throw ex; } else { return task.Result; } })); }
public int Commit() { BeforeCommit?.Invoke(this, new BeforeCommit()); int? changes = null; Exception exception = null; try { changes = uow.Commit(); } catch (Exception ex) { exception = ex; AfterCommit?.Invoke(this, new AfterCommit(changes, exception)); throw; // AfterSave might change the exception and throw, if not, do it ourself } finally { AfterCommit?.Invoke(this, new AfterCommit(changes, exception)); } return(changes.Value); }