【问题标题】:Azure .NET 5 isolated functions and how to update a table storage using function bindingAzure .NET 5 隔离函数以及如何使用函数绑定更新表存储
【发布时间】:2021-09-24 16:42:43
【问题描述】:

我正在尝试更新Azure .NET 5 isolated functions 中的一个表存储行,其中我使用了function binding(环境为Function v. 3)。

我复制了this example(参见下面的代码),但我找不到使用现有分区键更新“MyTableData”的方法。如果我尝试使用相同的分区键,则函数绑定不会执行“upsert”并且我总是会收到“Internal Server Error”。

你知道有没有办法通过函数绑定来管理更新和插入?

using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace SampleApp
{
    public static class TableFunction
    {
        [Function("TableFunction")]
        [TableOutput("OutputTable", Connection = "AzureWebJobsStorage")]
        public static MyTableData Run([QueueTrigger("table-items")] string input,
            [TableInput("MyTable", "MyPartition", "{queueTrigger}")] MyTableData tableInput,
            FunctionContext context)
        {
            var logger = context.GetLogger("TableFunction");

            logger.LogInformation($"PK={tableInput.PartitionKey}, RK={tableInput.RowKey}, Text={tableInput.Text}");

            return new MyTableData()
            {
                PartitionKey = "queue",
                RowKey = Guid.NewGuid().ToString(),
                Text = $"Output record with rowkey {input} created at {DateTime.Now}"
            };
        }
    }

    public class MyTableData
    {
        public string PartitionKey { get; set; }

        public string RowKey { get; set; }

        public string Text { get; set; }
    }
}

【问题讨论】:

标签: c# azure azure-functions .net-5


【解决方案1】:

使用 CloudTable 方法参数通过 Azure 存储 SDK 读取表。

CloudTable 仅在 Functions v2 and and higher runtimes 中受支持。

如果您尝试绑定到CloudTable 并收到错误消息,请确保您引用了the correct Storage SDK version

请参考thisAzure Table storage bindings 参考。

【讨论】:

  • 您好,感谢您的回复。 此解决方案在 .NET 工作人员隔离进程中不起作用,如果我尝试使用“表”属性,安装“Microsoft.Azure.WebJobs.Extensions.Storage”NuGet,我会得到错误:AZFW0001。我正在使用 .NET 5 隔离函数"Microsoft.Azure.Functions.Worker.Extensions.Storage" NuGet。谢谢
  • 新的 .NET worker 绑定工作 as explained here。您可以找到 some example here,但缺少解释如何执行更新或删除的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-31
  • 2020-08-09
  • 2023-04-09
  • 2022-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多