0

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;):

'TableContinuationToken' does not contain a definition for '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. 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);
}
Henry Zhu
  • 2,488
  • 9
  • 43
  • 87

1 Answers1

1

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.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241