示例#1
0
        private void RegistTransScopeConnection(DbConnectionWrap conn)
        {
            if (_TransScopeConnections.Value == null)
            {
                _TransScopeConnections.Value = new Stack <DbConnectionWrap>();
            }

            if (_TransScopeConnections.Value.Count == 0 || _TransScopeConnections.Value.Peek() != conn)
            {
                _TransScopeConnections.Value.Push(conn);
                LogDebug("Regist TransScope Connection(Root TransScope). DbConnectionWrap.Guid={0}", conn.Guid);
            }
        }
示例#2
0
        private DbConnectionWrap CreateConnectionWrap(bool isNew)
        {
            DbConnectionWrap wrapConn;

            //在TransScope范围中共用一个数据库连接对象
            if (_TransScopeConnections.Value != null && _TransScopeConnections.Value.Count > 0 && !isNew)
            {
                wrapConn = _TransScopeConnections.Value.Peek();
                LogDebug("Get a exist connection from TransScope. DbConnectionWrap.Guid={0}", wrapConn.Guid);
            }
            else
            {
                var conn = _DbFactory.CreateConnection();
                wrapConn = new DbConnectionWrap(conn, LoggerFactory);
                LogDebug("Create new connection. DbConnectionWrap.Guid={0}", wrapConn.Guid);
            }

            return(wrapConn);
        }