【问题标题】:Azure C# Function: How to read from Table StorageAzure C# 函数:如何从表存储中读取
【发布时间】:2020-07-17 15:53:01
【问题描述】:

我正在尝试使用 C# 函数从 Azure 表存储中读取数据,并遵循此答案 (How to get all rows in Azure table Storage in C#?) 中列出的指南。但是,在我的代码的最后一行,我收到以下错误:

CloudTable 不包含 ExecuteQuery 的定义

下面是我的代码:

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

我正在使用Azure Functions v2.0.NET Core SDK 3.1.302

【问题讨论】:

标签: c# azure


【解决方案1】:

你使用的包(Microsoft.WindowsAzure.Storage.Table)太旧了,微软现在主要支持这个包(Microsoft.Azure.Cosmos.Table)。你可以从这个link获取这个包,我已经为你测试过了,使用这个包可以达到你想要的效果。

你不需要改变你的代码,你只需要在导入包时注意使用我推荐的那个,它是这样的:

using Microsoft.Azure.Cosmos.Table;

您也可以使用此方法查询您的结果:

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

但它在一次调用中最多返回 1000 个实体。如果您的表中有超过 1000 个实体可用,它会返回一个可用于获取下一组实体的延续令牌。

更多详情可以参考本官方document

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多