public void UsingTransaction(IsolationLevel isolationLevel, Action <TransactionContext> action) { DbTransaction tran = null; try { tran = Connection.BeginTransaction(isolationLevel); action(ContextProvider.GetTransactionContext(tran, QueryOptions, BulkOptions, ReadOptions)); tran.Commit(); } catch { if (tran != null) { tran.Rollback(); } throw; } }
public async Task UsingTransactionAsync(IsolationLevel isolationLevel, Func <TransactionContext, Task> action) { DbTransaction tran = null; try { tran = Connection.BeginTransaction(isolationLevel); await action(ContextProvider.GetTransactionContext(tran, QueryOptions, BulkOptions, ReadOptions)).ConfigureAwait(false); tran.Commit(); } catch { if (tran != null) { tran.Rollback(); } throw; } }