1

I am trying to read from Azure Table Storage using a C# function, and am following the guidelines listed in this answer (How to get all rows in Azure table Storage in C#?). However, at the last line of my code, I get the following error:

CloudTable does not contain a definition for ExecuteQuery

Below is my code:

var creds = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(creds, useHttps: true);

// Retrieve the role assignments table
var client = account.CreateCloudTableClient();
var table = client.GetTableReference("RoleAssignmentTable");
var entities = table.ExecuteQuery(new TableQuery<RoleAssignment>()).ToList();

I am using Azure Functions v2.0 and .NET Core SDK 3.1.302

Henry Zhu
  • 2,488
  • 9
  • 43
  • 87
  • 1
    Looks like an issue with the .Net version you're targeting: https://github.com/Azure/azure-storage-net/issues/684 – Jeremy Thompson Jul 17 '20 at 00:42
  • You're probably not using the latest and correct connectivity .Net controls? https://www.nuget.org/profiles/azure-sdk – Fandango68 Jul 17 '20 at 01:02
  • might try var entities = (await table.ExecuteQuerySegmentedAsync(new TableQuery(), null)).ToList(); //presuming you are in an async method – Ron Jul 17 '20 at 04:05

1 Answers1

1

The package(Microsoft.WindowsAzure.Storage.Table) you use is too old, Microsoft is mainly support this package(Microsoft.Azure.Cosmos.Table) now. you can obtain this package from this link, and i have tested it for you, using this package can achieve the effect you want.

You do not need to change your code, you only need to pay attention to use the one I recommend when importing the package, and it like this:

using Microsoft.Azure.Cosmos.Table;

You can also use this method to query your results:

var queryResult = table.ExecuteQuerySegmentedAsync(new TableQuery<myEntity>(), Token).Result.ToList();

But it returns a maximum of 1000 entities in a single call. If there're more than 1000 entities available in your table, it returns a continuation token which can be used to fetch next set of entities.

For more details, you can refer to this official document.

Frank Borzage
  • 6,292
  • 1
  • 6
  • 19