Beispiel #1
0
 public UnitOfWorkScope(IUnitOfWorkFactory factory, IsolationLevel isolationLevel, UoWScopeOptions scopeOptions)
 {
     _useCompatibleEnabled = scopeOptions.Contains(UoWScopeOptions.UseCompatible);
     _disposed             = false;
     _factory            = factory;
     _transactionOptions = scopeOptions;
     _autoComplete       = (scopeOptions & UoWScopeOptions.AutoComplete) == UoWScopeOptions.AutoComplete;
     _currentTransaction = UnitOfWorkScopeTransaction.GetTransactionForScope(factory, this, isolationLevel, scopeOptions);
     RegisterScope(this);
 }
        public static UnitOfWorkScopeTransaction GetTransactionForScope(IUnitOfWorkFactory factory, UnitOfWorkScope scope, IsolationLevel isolationLevel, UoWScopeOptions options)
        {
            var useCompatibleTx = (options & UoWScopeOptions.UseCompatible) == UoWScopeOptions.UseCompatible;
            var createNewTx     = (options & UoWScopeOptions.CreateNew) == UoWScopeOptions.CreateNew;

            //вот нельзя одновременно создавать новую транзакцию и использовать существующую
            if (useCompatibleTx && createNewTx)
            {
                throw new InvalidOperationException("Несовместимые опции запуска транзакции");
            }

            if (options == UoWScopeOptions.UseCompatible)
            {
                var transaction = (from t in CurrentTransactions where t.IsolationLevel == isolationLevel select t).FirstOrDefault();
                if (transaction != null)
                {
                    transaction.AttachScope(scope);
                    return(transaction);
                }
            }

            var newTransaction = new UnitOfWorkScopeTransaction(factory, isolationLevel);

            newTransaction.AttachScope(scope);
            CurrentTransactions.AddFirst(newTransaction);
            return(newTransaction);
        }
Beispiel #3
0
 public UnitOfWorkScope(IUnitOfWorkFactory factory, UoWScopeOptions options)
     : this(factory, GetScopeIsolationLevel(), options)
 {
 }