每次请求 10 个项目的 azure 表存储分页 [英] azure table storage pagination for request 10 items each time

查看:24
本文介绍了每次请求 10 个项目的 azure 表存储分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,当请求 Azure 表存储实体时,我试图让分页工作.即按下一步按钮获取接下来的 10 个实体 &按上一个按钮获取前 10 个实体.一个相对接近的例子 Gaurav Mantri 的答案.但我的问题是如何获得 nextPartitionKeynextRowKey 来自 HTML 按钮属性并存储到数组/列表中以跟踪当前页面,以便我可以获取下一个/以前的项目?代码示例将不胜感激.谢谢!

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 gets the previous 10 entities. A relatively close example Gaurav Mantri's Answer. But my question is how do I get the nextPartitionKey and nextRowKey from a HTML button attribute and store in to a array/list in order to keep track of current page so I can get the next/previous items?Code example would be very appreciated. Thanks!

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

This is something I have right now which gets a range of data based on pageNumber request

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;
    }

推荐答案

在 Gaurav 的帮助下设法解决了问题.这是代码,不完美但有效.

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

并使用元组声明它.

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

这篇关于每次请求 10 个项目的 azure 表存储分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆