简体   繁体   English

Azure C# v2 Function:TableContinuationToken 不包含 ContinuationToken 的定义

[英]Azure C# v2 Function: TableContinuationToken does not contain a definition for ContinuationToken

I am trying to read the first ten rows of an Azure Table Storage using Azure v2 C# Function + .NET Core SDK 3.1. I am trying to read the first ten rows of an Azure Table Storage using Azure v2 C# Function + .NET Core SDK 3.1. However, I get the following error in this line of code ( token = token.ContinuationToken; ):但是,我在这行代码( token = token.ContinuationToken; )中收到以下错误:

'TableContinuationToken' does not contain a definition for 'ContinuationToken' “TableContinuationToken”不包含“ContinuationToken”的定义

However, this doesn't make much sense considering that in this answer ( How to get all rows in Azure table Storage in C#? ), the writer of that answer retrieved the ContinuationToken attribute from a TableContinuationToken object.但是,考虑到在这个答案( How to get all rows in Azure table Storage in C#? )中,这没有多大意义,该答案的作者从TableContinuationToken ZA8CFDE6331BD59EB62AC1 中检索了ContinuationToken属性Below is my code:下面是我的代码:

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 = table.ExecuteQuerySegmentedAsync(new TableQuery<RoleAssignment>(), token);
    tablePortion.AddRange(queryResult.Result);
    token = token.ContinuationToken;
    rowCount++;
} while (rowCount < 10);

// Print out the contents of the table
foreach (RoleAssignment role in tablePortion)
{
    Console.WriteLine(role.Timestamp);
}

Please change the following line:请更改以下行:

token = token.ContinuationToken;

to

token = queryResult.ContinuationToken;

UPDATE更新

Please try the following code:请尝试以下代码:

do
{
    var queryResult = await table.ExecuteQuerySegmentedAsync(new TableQuery<RoleAssignment>(), token);
    tablePortion.AddRange(queryResult.Result);
    token = queryResult.ContinuationToken;
    rowCount++;
} while (rowCount < 10);

Essentially you're not awaiting an async operation.本质上,您不是在awaiting async操作。

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

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