public static async Task <PagedResult <TEntity> > GetPagedQueryResultsAsync <TEntity>(
            this IDynamoDBContext dynamoDbContext, QueryOperationConfig queryConfig) where TEntity : class
        {
            var dbResults = new List <TEntity>();
            var table     = dynamoDbContext.GetTargetTable <TEntity>();

            var search     = table.Query(queryConfig);
            var resultsSet = await search.GetNextSetAsync().ConfigureAwait(false);

            var paginationToken = search.PaginationToken;

            if (resultsSet.Any())
            {
                dbResults.AddRange(dynamoDbContext.FromDocuments <TEntity>(resultsSet));

                // Look ahead for any more, but only if we have a token
                if (!string.IsNullOrEmpty(PaginationDetails.EncodeToken(paginationToken)))
                {
                    queryConfig.PaginationToken = paginationToken;
                    queryConfig.Limit           = 1;
                    search     = table.Query(queryConfig);
                    resultsSet = await search.GetNextSetAsync().ConfigureAwait(false);

                    if (!resultsSet.Any())
                    {
                        paginationToken = null;
                    }
                }
            }

            return(new PagedResult <TEntity>(dbResults, new PaginationDetails(paginationToken)));
        }
Ejemplo n.º 2
0
 public PagedResult(IEnumerable <T> results, PaginationDetails paginationDetails)
 {
     if (null != results)
     {
         Results.AddRange(results);
     }
     PaginationDetails = paginationDetails;
 }