尝试从表存储中检索所有行我的代码就像文档中的那样
using Microsoft.Azure.Cosmos.Table;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public class TableStorage
{
public class MyPoco : TableEntity
{
public string Text { get; set; }
public object PartitionKey { get; internal set; }
public object RowKey { get; internal set; }
}
[FunctionName("TableInput")]
public static void TableInput(
[QueueTrigger("table-items")] string input,
[Table("MyTable")] IQueryable<MyPoco> pocos,
ILogger log)
{
foreach (MyPoco poco in pocos)
{
log.LogInformation($"PK={poco.PartitionKey}, RK={poco.RowKey}, Text={poco.Text}");
}
}
}
错误是: 严重性代码 说明 项目文件行抑制状态 错误 CS0592 属性“表”在此声明类型上无效。它仅对“类”声明有效。
我还缺少什么?
最佳答案
TableAttribute
现在从 System.ComponentModel.DataAnnotations.Schema
解析,而不是从正确的位置(即 Microsoft.Azure.WebJobs)解析
。请参阅TableAttribute Class对于错误的属性。
为此,请确保您为 NuGet 包 Microsoft.Azure.WebJobs.Extensions.Storage 安装了正确的版本 (4.0.5)。 .
版本 5.0.0 删除了 TableAttribute
。我认为它将以 Cosmos DB 包的形式回归,但还没有抽出时间来找出是哪一个。然而。
编辑:
仅在 Functions v1 运行时支持使用表绑定(bind)到 IQueryable
。如果您不是在 v1 运行时上运行,则可以绑定(bind)到整个 CloudTable
,或者通过在绑定(bind)中提供分区键和行键来指定表中的一项特定项目。
此外:您的 POCO 属性 PartitionKey
和 RowKey
隐藏了 TableEntity
中的属性。如果这是有意为之,您可能需要通过添加 new
关键字来明确这一点。
关于c# - Azure 函数从 Azure 表存储检索行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70852234/