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

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

问题描述

基本上,我正在尝试在请求天蓝色表存储实体时进行分页.即按下一步"按钮可获取下一个10个实体&按下上一个按钮可获得前10个实体.一个相对较近的示例 Gaurav Mantri的答案.但是我的问题是如何获得

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个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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