/// <summary> /// 提交事务 /// </summary> public void Commit() { if (!isRealTransaction) { return; } BeforeCommit?.Invoke(); Transaction?.Commit(); AfterCommit?.Invoke(); }
public void Commit(Database db = null) { db = db ?? Database; SqlStringBuilder sql = db.ServiceProvider.Get <SqlStringBuilder>(); WriteCommit(sql); sql.Execute(db); AfterCommit?.Invoke(db, this); }
public void WriteCommit(SqlStringBuilder sql, Database db = null) { db = db ?? Database; List <L> children = new List <L>(); foreach (L item in this._values) { EnsureXref(item, db); item.WriteCommit(sql, db); children.Add(item); } sql.Executed += (s, d) => { children.Each(dao => dao.OnAfterCommit(d)); AfterCommit?.Invoke(d, this); }; }
public void WriteCommit(SqlStringBuilder sql, Database db = null) { db = db ?? Database; List <T> children = new List <T>(); foreach (T dao in this._values) { if (dao.HasNewValues) { dao.WriteCommit(sql, db); children.Add(dao); } } sql.Executed += (s, d) => { children.Each(dao => dao.OnAfterCommit(d)); AfterCommit?.Invoke(d, this); }; }
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 async Task <bool> CommitAsync() { try { var result = await _context.SaveChangesAsync() >= 0; if (result) { AfterCommit?.Invoke(); } return(result); } catch { throw; } finally { AfterCommit = null; } }
public bool Commit() { try { var result = _context.SaveChanges() >= 0; if (result) { AfterCommit?.Invoke(); } return(result); } catch { throw; } finally { AfterCommit = null; } }
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); }