简体   繁体   中英

Azure C# Function: How to read from Table Storage

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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