azure table storage pagination for request 10 items each time

前端 未结 1 337
小鲜肉
小鲜肉 2021-01-28 08:56

Basically I am trying to get pagination working when requesting entities of azure table storage. i.e. Press next button gets the next 10 entities & Press previous button get

相关标签:
1条回答
  • 2021-01-28 09:18

    Managed to solved the problem under Gaurav's help. Here is the code, not perfect but works.

    private async Task<List<UserInfo>> queryPage(CloudTable peopleTable, string item, string NextPartitionKey , string NextRowKey, int itemNumber)
        {
            // Construct the query operation for all customer entities 
            TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, item)).Take(itemNumber);
    
    
            // Print the fields for each customer.
            List<UserInfo> data = new List<UserInfo>();
    
            Tabletoken.NextPartitionKey = NextPartitionKey;
            Tabletoken.NextRowKey = NextRowKey;
            TableQuerySegment<CustomerEntity> resultSegment = await peopleTable.ExecuteQuerySegmentedAsync(query, Tabletoken);
            Tabletoken = resultSegment.ContinuationToken;
    
    
            foreach (CustomerEntity entity in resultSegment.Results)
            {
    
                data.Add(new UserInfo
                {
                    //add data
                });
    
            }
    
            return data;
        }
    
        private TableContinuationToken Tabletoken = new TableContinuationToken();
    

    and declare it use a tuple.

     Tuple<List<UserInfo>, string, string > tuple =
                    new Tuple<List<UserInfo>, string, string>(data, Tabletoken.NextPartitionKey, Tabletoken.NextRowKey);
    
    0 讨论(0)
提交回复
热议问题