Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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;
            }
        }