/// <summary>
        /// Executes the command asynchronously
        /// </summary>
        /// <param name="request">The command request</param>
        /// <param name="cancellationToken">The cancellation token in scope for the operation</param>
        /// <returns>The result of the command</returns>
        public async Task <PaginationResult> ExecuteAsync(PaginationRequest request, CancellationToken cancellationToken)
        {
            string sqlPagination      = GetPaginationSql(request);
            string sqlPaginationCount = GetSqlRequestCount(request);

            // These 2 database commands can be executed in parallel
            Task <DataTable> getDataTask  = _databaseCommander.ExecuteSqlAsync(sqlPagination, cancellationToken);
            Task <int>       getCountTask = _databaseCommander.ExecuteScalarAsync <int>(sqlPaginationCount, cancellationToken);

            await Task.WhenAll(getDataTask, getCountTask);

            // Get the results of the commands executed asynchronously
            DataTable dataTable  = await getDataTask;
            int       totalCount = await getCountTask;

            return(new PaginationResult(dataTable, totalCount));
        }
예제 #2
0
 public override async Task <TResult> ExecuteAsync(CancellationToken cancellationToken)
 {
     return(await _databaseCommander.ExecuteScalarAsync <TResult>((ScalarRequest)CommandRequest, cancellationToken));
 }