Beispiel #1
0
        /// <summary>
        /// Summarizes the target field from all data of the database table in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="SumAllRequest"/> object.</param>
        /// <param name="param">The mapped object parameters.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <returns>An integer value that holds the number of data from the database.</returns>
        internal static async Task <object> SumAllInternalAsyncBase(this IDbConnection connection,
                                                                    SumAllRequest request,
                                                                    object param,
                                                                    int?commandTimeout         = null,
                                                                    IDbTransaction transaction = null,
                                                                    ITrace trace = null)
        {
            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetSumAllText(request);

            // Before Execution
            if (trace != null)
            {
                var cancellableTraceLog = new CancellableTraceLog(commandText, param, null);
                trace.BeforeSumAll(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(default(int));
                }
                commandText = (cancellableTraceLog.Statement ?? commandText);
                param       = (cancellableTraceLog.Parameter ?? param);
            }

            // Before Execution Time
            var beforeExecutionTime = DateTime.UtcNow;

            // Actual Execution
            var result = await ExecuteScalarAsyncInternal <object>(connection : connection,
                                                                   commandText : commandText,
                                                                   param : param,
                                                                   commandType : commandType,
                                                                   commandTimeout : commandTimeout,
                                                                   transaction : transaction,
                                                                   skipCommandArrayParametersCheck : true);

            // After Execution
            if (trace != null)
            {
                trace.AfterSumAll(new TraceLog(commandText, param, result,
                                               DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

            // Result
            return(result);
        }