コード例 #1
0
        protected virtual IDbExecuteContext Execute(NpgsqlCommand command, IDbTracing tracing)
        {
            try
            {
                TryExecuteTracing(tracing, t => t.OnExecuting(command));

                var connection = new NpgsqlConnection(this.ConnectionString);
                connection.Open();
                command.Connection = connection;

                if (Configuration.QueryExecutingTimeout.HasValue)
                {
                    command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds;
                }


                var reader  = command.ExecuteReader();
                var context = new NpgsqlDbExecuteContext(connection, reader, tracing);

                TryExecuteTracing(tracing, t => t.OnLoadingData(context));

                return(context);
            }
            catch (DbException exception)
            {
                TryExecuteTracing(tracing, t => t.OnException(exception));
                throw;
            }
        }
コード例 #2
0
            /// <summary>
            /// 重写 ExecuteAsync 方法,在事务中异步执行查询
            /// </summary>
            /// <param name="command">要执行的查询命令</param>
            /// <param name="token">取消指示</param>
            /// <param name="tracing">用于追踪的追踪器</param>
            /// <returns>查询执行上下文</returns>
            protected sealed override async Task <IAsyncDbExecuteContext> ExecuteAsync(NpgsqlCommand command, CancellationToken token, IDbTracing tracing = null)
            {
                try
                {
                    TryExecuteTracing(tracing, t => t.OnExecuting(command));

                    command.Connection  = TransactionContext.Connection;
                    command.Transaction = TransactionContext.Transaction;

                    if (Configuration.QueryExecutingTimeout.HasValue)
                    {
                        command.CommandTimeout = (int)Configuration.QueryExecutingTimeout.Value.TotalSeconds;
                    }


                    var reader = await command.ExecuteReaderAsync(token);

                    var context = new NpgsqlDbExecuteContext(TransactionContext, reader, tracing);

                    TryExecuteTracing(tracing, t => t.OnLoadingData(context));

                    return(context);
                }
                catch (DbException exception)
                {
                    TryExecuteTracing(tracing, t => t.OnException(exception));

                    throw;
                }
            }
コード例 #3
0
        /// <summary>
        /// 执行查询命令并返回执行上下文
        /// </summary>
        /// <param name="command">查询命令</param>
        /// <param name="tracing">用于追踪查询过程的追踪器</param>
        /// <returns>查询执行上下文</returns>
        protected sealed override IDbExecuteContext Execute(NpgsqlCommand command, IDbTracing tracing = null)
        {
            try
            {
                TryExecuteTracing(tracing, t => t.OnExecuting(command));

                command.Connection  = TransactionContext.Connection;
                command.Transaction = TransactionContext.Transaction;

                var reader  = command.ExecuteReader();
                var context = new NpgsqlDbExecuteContext(TransactionContext, reader, tracing);

                TryExecuteTracing(tracing, t => t.OnLoadingData(context));

                return(context);
            }
            catch (DbException exception)
            {
                TryExecuteTracing(tracing, t => t.OnException(exception));
                throw;
            }
        }