简体   繁体   中英

Get complete table with all datasets from Azure Table Storage with v4 Function Apps in C#

With older versions of .NET and Azure Function Apps v2 it was possible to get all datasets from an Azure Table Storage table using (among other things) a TableContinuationToken: Get more than 1000 datasets from an Azure Table Storage

Since the underlying Microsoft.Azure.Cosmos.Table packages are deprecated:

What is the new, current way in an .NET 6 based v4 Azure Function App to get all datasets from a table in an Azure Table Storage?

I have reproduced the issue in my environment and able to fetch the data list.

Thanks @ Gaurav Mantri for the comment.

  1. create a storage account and table in azure.在此处输入图像描述

I used the below code and able to fetch the data list

private void tableInsert()
        {

            CloudStorageAccount storage_Account = CloudStorageAccount.Parse(storageAccount_connectionString);
            CloudTableClient tableClient = storage_Account.CreateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("table1");


            for (int ctr = 0; ctr < 1000; ctr++)
            {
                EmployeeEntity employeeEntity = new EmployeeEntity("Fname"+ctr, "LName"+ctr)
                {
                    Email = "something@something.com",
                    PhoneNumber = "123456789"

                };

                TableOperation insertOperation = TableOperation.Insert(employeeEntity);
                table.ExecuteAsync(insertOperation);
            }
           
        }

for fetching

 public async Task<List<TableEntity>> GetList()
        {
            
            CloudTable table = await GetTableAsync();
            
            TableQuery<TableEntity> query = new TableQuery<TableEntity>();
            List<TableEntity> results = new List<TableEntity>();
            TableContinuationToken continuationToken = null;
            do
            {
                TableQuerySegment<TableEntity> queryResults = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
                continuationToken = queryResults.ContinuationToken;
                results.AddRange(queryResults.Results);
            } while (continuationToken != null);
            return results;
        }
        private async Task<CloudTable> GetTableAsync()
        {
            
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccount_connectionString);
            
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("table1");
            await table.CreateIfNotExistsAsync();
            return table;
        }

在此处输入图像描述

Reference taken from Azure Tables client library for .NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM