Example #1
0
        /// <summary>
        /// 使用指定锁定行为启动一个数据库事务。
        /// </summary>
        /// <param name="level">事务的锁定行为。</param>
        /// <returns>如果当前实例首次启动事务,则为 true,否则为 false。</returns>
        public virtual bool BeginTransaction(IsolationLevel level = IsolationLevel.ReadCommitted)
        {
            tranStack.Push();
            if (Transaction != null)
            {
                return(false);
            }

            if (TransactionScopeConnections.GetConnection(this) != null)
            {
                return(false);
            }

            Connection.TryOpen();
            Transaction = Connection.BeginTransaction(level);

            return(true);
        }
Example #2
0
        /// <summary>
        /// 使用指定锁定行为启动一个数据库事务。
        /// </summary>
        /// <param name="level">事务的锁定行为。</param>
        /// <returns>如果当前实例首次启动事务,则为 true,否则为 false。</returns>
        public virtual bool BeginTransaction(IsolationLevel level = IsolationLevel.ReadCommitted)
        {
            if (Transaction != null)
            {
                return(false);
            }

            if (TransactionScopeConnections.GetConnection(this) != null)
            {
                return(false);
            }

            Connection.TryOpen();
            Tracer.Debug("Starting transcation.");
            _transaction      = Connection.BeginTransaction(Provider.AmendIsolationLevel(level));
            _transactionScope = new DbTransactionScope(ConnectionString, _transaction);

            return(true);
        }