/// <summary> /// 进入一个事务上下文 /// </summary> /// <param name="transaction">要进入的事务</param> /// <returns>事务上下文</returns> public static IDatabaseTransaction EnterTransaction(IDatabaseTransaction transaction) { if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } var context = DbContext.EnterContext(transaction); transaction.RegisterDispose(context); transaction.BeginTransaction(); return(transaction); }
/// <summary> /// 异步进入一个事务上下文 /// </summary> /// <param name="transaction">要进入的事务,若事务是异步事务,则会异步开启,否则将同步开启</param> /// <returns>事务上下文</returns> public static async ValueTask <IDatabaseTransaction> EnterTransactionAsync(IDatabaseTransaction transaction) { if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } var context = DbContext.EnterContext(transaction); transaction.RegisterDispose(context); if (transaction is IAsyncDatabaseTransaction async) { await async.BeginTransactionAsync(); } else { transaction.BeginTransaction(); } return(transaction); }
public void BeginTransaction() => _context.BeginTransaction();