简体   繁体   English

Azure function 从 Azure 表存储中检索行

[英]Azure function retrieve row from Azure table storage

trying to retrieve all rows from table storage my code is like this like in the documentation试图从表存储中检索所有行我的代码就像在文档中一样

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}");
        }
    }
}

the error is: Severity Code Description Project File Line Suppression State Error CS0592 Attribute 'Table' is not valid on this declaration type.错误是:严重性代码描述项目文件行抑制 State 错误 CS0592 属性“表”在此声明类型上无效。 It is only valid on 'class' declarations.它仅对“类”声明有效。

What al I missing?我错过了什么?

The TableAttribute is now resolved from System.ComponentModel.DataAnnotations.Schema instead of it being resolved from the correct location, which is Microsoft.Azure.WebJobs . TableAttribute现在从System.ComponentModel.DataAnnotations.Schema解析,而不是从正确的位置解析,即Microsoft.Azure.WebJobs See TableAttribute Class for the faulty attribute.故障属性见TableAttribute Class

For this to work, please make sure you have the correct version (4.0.5) installed for NuGet package Microsoft.Azure.WebJobs.Extensions.Storage .为此,请确保为 NuGet package Microsoft.Azure.WebJobs.Extension安装了正确的版本 (4.0.5)

Version 5.0.0 removes the TableAttribute . 5.0.0 版删除了TableAttribute I think it will come back in a Cosmos DB package, but haven't gotten around to finding out which one.我认为它会在 Cosmos DB package 中回归,但还没有找到答案。 Yet.然而。

EDIT:编辑:
Using a table binding to an IQueryable is only supported in the Functions v1 runtime.仅在 Functions v1 运行时支持使用表绑定到IQueryable If you are not running on the v1 runtime, you can either bind to an entire CloudTable , or to one specific item in the table by providing both partition key and row key in the binding.如果您没有在 v1 运行时上运行,您可以绑定到整个CloudTable或通过在绑定中提供分区键和行键来绑定到表中的一个特定项目。

Also: your POCO properties PartitionKey and RowKey hide the ones from TableEntity .另外:您的 POCO 属性PartitionKeyRowKey隐藏了TableEntity中的属性。 If that's intentional, you might want to make that explicit by adding a new keyword.如果这是故意的,您可能希望通过添加new关键字来明确这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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