c# - Azure 函数从 Azure 表存储检索行

标签 c# azure function azure-storage

尝试从表存储中检索所有行我的代码就像文档中的那样

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 属性 PartitionKeyRowKey 隐藏了 TableEntity 中的属性。如果这是有意为之,您可能需要通过添加 new 关键字来明确这一点。

关于c# - Azure 函数从 Azure 表存储检索行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70852234/

相关文章:

javascript - 创建多次使用的函数

c++ - 在 C++ 中,如何在继续执行整个程序的同时延迟程序的一部分?

c - C 中的返回值

azure - Service Fabric 单例服务在扩展时是否会出现停机?

azure - Web 数据库的性能似乎比新的 Azure SQL DB 服务层更快?

c# - HttpClient 处理加密的细节是什么?

c# - 具有未分配的变量参数的 linq

azure - 内存使用量攀升,但仅限于应用服务计划

c# - Microsoft Band 2 支持的报告间隔

c# - C#/.NET 4.0 中新的 NoPIA 和类型等效功能是否意味着不再需要 Microsoft.mshtml.dll