azure table存储分页请求每次10项

时间:2018-04-03 02:19:43

标签: azure pagination azure-storage

基本上我在尝试使用azure表存储的实体时尝试分页。即按下一个按钮获得下一个10个实体&按上一个按钮可获得前10个实体。一个相对接近的例子Gaurav Mantri's Answer。但我的问题是如何从HTML按钮属性获取nextPartitionKeynextRowKey并存储到数组/列表中以跟踪当前页面,以便我可以获取下一个/上一个项目?代码示例将非常感激。 谢谢!

这是我现在所拥有的,它根据pageNumber请求获取一系列数据

private async Task<List<UserInfo>> queryPage(CloudTable peopleTable, string item, int pageNumber)
    {
        // Construct the query operation for all customer entities 
        TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, item));

        // Print the fields for each customer.
        TableContinuationToken token = null;
        //TodoItem data = new TodoItem();
        List<UserInfo> data = new List<UserInfo>();

        do
        {
            TableQuerySegment<CustomerEntity> resultSegment = await peopleTable.ExecuteQuerySegmentedAsync(query, token);
            token = resultSegment.ContinuationToken;

            foreach (CustomerEntity entity in resultSegment.Results)
            {

                data.Add(new UserInfo
                {
                    // add data
                });

            }
        } while (token != null);

        //get a subset of all entity
        List<UserInfo> sublist = data.GetRange(0, pageNumber);



        return sublist;
    }

1 个答案:

答案 0 :(得分:0)

在Gaurav的帮助下管理解决问题。 这是代码,不完美但有效。

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();

并声明它使用元组。

 Tuple<List<UserInfo>, string, string > tuple =
                new Tuple<List<UserInfo>, string, string>(data, Tabletoken.NextPartitionKey, Tabletoken.NextRowKey);