我正在编写一个基本的 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/