简体   繁体   English

从 Azure 获取包含所有数据集的完整表格 Table Storage with v4 Function Apps in C#

[英]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使用 .NET 和 Azure Function Apps v2 的旧版本,可以使用(除其他外)TableContinuationToken 从 Azure 表存储表中获取所有数据集:从 Azure 表存储中获取超过 1000 个数据集

Since the underlying Microsoft.Azure.Cosmos.Table packages are deprecated:由于底层 Microsoft.Azure.Cosmos.Table 包已弃用:

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?在基于 .NET 6 的 v4 Azure Function 应用程序中,从 Azure 表存储中的表中获取所有数据集的新方法是什么?

I have reproduced the issue in my environment and able to fetch the data list.我已经在我的环境中重现了这个问题并且能够获取数据列表。

Thanks @ Gaurav Mantri for the comment.感谢Gaurav Mantri的评论。

  1. create a storage account and table in azure.在 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参考取自Azure Tables 客户端库 .NET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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