/// <summary> /// Count the number of rows from the table in an asynchronous way. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="request">The actual <see cref="CountAllRequest"/> 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> /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param> /// <returns>An integer value that holds the number of rows from the table.</returns> internal static async Task <long> CountAllAsyncInternalBase(this IDbConnection connection, CountAllRequest request, object param, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; var commandText = CommandTextCache.GetCountAllText(request); var sessionId = Guid.Empty; // Before Execution if (trace != null) { sessionId = Guid.NewGuid(); var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null); trace.BeforeCountAll(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 <long>(connection : connection, commandText : commandText, param : param, commandType : commandType, cacheKey : null, cacheItemExpiration : null, commandTimeout : commandTimeout, transaction : transaction, cache : null, cancellationToken : cancellationToken, entityType : request.Type, dbFields : await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck : true); // After Execution if (trace != null) { trace.AfterCountAll(new TraceLog(sessionId, commandText, param, result, DateTime.UtcNow.Subtract(beforeExecutionTime))); } // Result return(result); }
/// <summary> /// CountAlls the number of table data from the database in an asynchronous way. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="request">The actual <see cref="CountAllRequest"/> 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 <long> CountAllInternalAsyncBase(this IDbConnection connection, CountAllRequest request, object param, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null) { // Validate InvokeValidatorValidateCountAllAsync(connection); // Variables var commandType = CommandType.Text; var commandText = CommandTextCache.GetCountAllText(request); // Before Execution if (trace != null) { var cancellableTraceLog = new CancellableTraceLog(commandText, param, null); trace.BeforeCountAll(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 <long>(connection : connection, commandText : commandText, param : param, commandType : commandType, commandTimeout : commandTimeout, transaction : transaction, skipCommandArrayParametersCheck : true); // After Execution if (trace != null) { trace.AfterCountAll(new TraceLog(commandText, param, result, DateTime.UtcNow.Subtract(beforeExecutionTime))); } // Result return(result); }