/// <summary> /// 提交 /// </summary> /// <param name="ctx"></param> public static void Commit(TranContext ctx) { ctx.Tran.Commit(); ctx.Database.Connection.Close(); ctx.Dispose(true); ctx.IsDisposed = true; }
/// <summary> /// 回滚 /// </summary> /// <param name="ctx"></param> public static void Rollback(TranContext ctx) { ctx.Tran.Rollback(); ctx.Database.Connection.Close(); ctx.Dispose(true); ctx.IsDisposed = true; }
/// <summary> /// 开始事务 /// </summary> /// <returns></returns> public static TranContext BeginTran() { TranContext ctx = new TranContext(); ctx.IsDisposed = false; ctx.Database.Connection.Open(); DbConnection con = ((IObjectContextAdapter)ctx).ObjectContext.Connection; ctx.Tran = con.BeginTransaction(); return ctx; }