c# - Azure C# v2 函数 : Entire table processed instead of portion of table

标签 c# azure

我正在编写一个基本的 C# Azure v2 计时器函数,以便读取 Azure 存储表的前十行。但是,当我运行程序时,存储角色分配的列表 (tablePortion) 的大小为 10000。考虑到我的 while 循环仅进行 10 次迭代,这看起来很奇怪。下面是我的代码:

public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("%TimerTriggerPeriod%")]TimerInfo myTimer, ILogger log)
{
    // Authenticate access into the database's Azure Table Storage
    StorageCredentials creds = new StorageCredentials(accountName, accountKey);
    CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);

    // Retrieve the role assignments table
    CloudTableClient client = account.CreateCloudTableClient();
    CloudTable table = client.GetTableReference("OneAuthZRoleAssignments");

    // Test out retrieving a small portion from the role assignments table (10 rows)
    var tablePortion = new List<RoleAssignment>();
    TableContinuationToken token = null;
    var rowCount = 0;
    do
    {
        var queryResult = await table.ExecuteQuerySegmentedAsync(new TableQuery<RoleAssignment>(), token);
        tablePortion.AddRange(queryResult.Results);
        token = queryResult.ContinuationToken;
        rowCount++;
    } while (rowCount < 10);

    Console.WriteLine(tablePortion.Count); // Output: 10000
}

最佳答案

所以你的程序工作正常,因为它按照你的要求做。

当调用 table.ExecuteQuerySegmentedAsync 方法时,您向其发送一个新的 TableQuery 实例,而不指定过滤器或分页,这意味着它将返回 1,000 个项目的默认数量(也是最大数量) - 如 docs 中所述

如果您只想接收 10 个项目,则可以在 while 循环之外进行调用,并在为 TableQuery 创建过滤器时发送 10 个分页。

关于c# - Azure C# v2 函数 : Entire table processed instead of portion of table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62948124/

相关文章:

c# - 重命名文件时重命名 XAML 文件类的更好方法?

具有自定义事件访问器的 C# 事件(添加和删除)

c# - 覆盖静态类的最佳实践

azure - 我是否对 azure 函数期望过高的可扩展性?

azure - 如何在 Office 365 API 上过滤来自特定电子邮件地址的电子邮件?

c# - 是否可以声明许多具有不同类型的泛型委托(delegate)的集合?

c# - 这两个片段中哪一个使用更多内存?

c# - 让 IIS 托管 WCF 服务中的流式传输正常工作

azure - 打开 github PR 时未触发 pr(Azure 管道 YAML)

azure - kubernetes集群可以共享windows和linux节点吗?