Beispiel #1
0
        void ReturnObject()
        {
            if (string.IsNullOrEmpty(this.Id) == false && DebugBeingUsed.TryRemove(this.Id, out var old))
            {
                this.Id = null;
            }

            _fsql.Ado.MasterPool.Return(_conn);
            _tran = null;
            _conn = null;
            EntityChangeReport?.Report.Clear();
        }
Beispiel #2
0
        public DbTransaction GetOrBeginTransaction(bool isCreate = true)
        {
            if (_tran != null)
            {
                return(_tran);
            }
            if (isCreate == false)
            {
                return(null);
            }
            if (!Enable)
            {
                return(null);
            }
            if (_conn != null)
            {
                _fsql.Ado.MasterPool.Return(_conn);
            }

            _tranBefore = new Aop.TraceBeforeEventArgs("BeginTransaction", IsolationLevel);
            _fsql?.Aop.TraceBeforeHandler?.Invoke(this, _tranBefore);
            try
            {
                _conn = _fsql.Ado.MasterPool.Get();
                try
                {
                    _tran = IsolationLevel == null?
                            _conn.Value.BeginTransaction() :
                                _conn.Value.BeginTransaction(IsolationLevel.Value);

                    this.Id = $"{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_{Interlocked.Increment(ref _seed)}";
                    DebugBeingUsed.TryAdd(this.Id, this);
                }
                catch
                {
                    ReturnObject();
                    throw;
                }
            }
            catch (Exception ex)
            {
                _fsql?.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(_tranBefore, "失败", ex));
#pragma warning disable CA2200 // 再次引发以保留堆栈详细信息
                throw ex;
#pragma warning restore CA2200 // 再次引发以保留堆栈详细信息
            }
            return(_tran);
        }
Beispiel #3
0
        public DbTransaction GetOrBeginTransaction(bool isCreate = true)
        {
            if (_tran != null)
            {
                return(_tran);
            }
            if (isCreate == false)
            {
                return(null);
            }
            if (!Enable)
            {
                return(null);
            }
            if (_conn != null)
            {
                _fsql.Ado.MasterPool.Return(_conn);
            }

            _conn = _fsql.Ado.MasterPool.Get();
            try
            {
                _tran = IsolationLevel == null?
                        _conn.Value.BeginTransaction() :
                            _conn.Value.BeginTransaction(IsolationLevel.Value);

                this.Id = $"{DateTime.Now.ToString("yyyyMMdd_HHmmss")}_{Interlocked.Increment(ref _seed)}";
                DebugBeingUsed.TryAdd(this.Id, this);
            }
            catch
            {
                ReturnObject();
                throw;
            }
            return(_tran);
        }