azure table storage pagination for request 10 items each time

放肆的年华 提交于 2020-01-06 06:44:58

问题


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!

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

回答1:


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


来源:https://stackoverflow.com/questions/49621281/azure-table-storage-pagination-for-request-10-items-each-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!