Azure C#v2函数:处理整个表而不是表的一部分
为了读取Azure存储表的前十行,我正在编写一个基本的C#Azure v2计时器函数。但是,当我运行程序时,存储角色分配的列表(Azure C#v2函数:处理整个表而不是表的一部分,c#,azure,C#,Azure,为了读取Azure存储表的前十行,我正在编写一个基本的C#Azure v2计时器函数。但是,当我运行程序时,存储角色分配的列表(tablepart)的大小是10000。考虑到我的while循环只进行了10次迭代,这似乎很奇怪。下面是我的代码: public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("%TimerTriggerPeriod%")]TimerInfo myTimer, ILog
tablepart
)的大小是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
}
public static async System.Threading.Tasks.Task RunAsync([TimerTrigger(“%TimerTriggerPeriod%”)TimerInfo myTimer,ILogger日志)
{
//验证对数据库Azure表存储的访问权限
StorageCredentials creds=新的StorageCredentials(accountName,accountKey);
CloudStorageAccount=新的CloudStorageAccount(creds,useHttps:true);
//检索角色分配表
CloudTableClient=account.CreateCloudTableClient();
CloudTable=client.GetTableReference(“OneAuthZRoleAssignments”);
//测试从角色分配表中检索一小部分(10行)
var tablepartment=新列表();
TableContinuationToken=空;
var rowCount=0;
做
{
var queryResult=await table.ExecuteQuerySegmentedAsync(new TableQuery(),token);
TableParty.AddRange(queryResult.Results);
token=queryResult.ContinuationToken;
行计数++;
}而(行数<10);
Console.WriteLine(tablepartment.Count);//输出:10000
}
因此您的程序运行良好,因为它执行您要求它执行的操作
调用table.ExecuteQuerySegmentedAsync方法时,您可以向它发送一个新的TableQuery实例,而不指定筛选器或分页,这意味着它将返回1000项的默认金额(也是最大金额),如中所述
如果您希望只接收10个项目,则可以在while循环之外进行调用,并在为TableQuery创建筛选器时发送10的分页