Azure Functions Table Binding: How do I update a row?

前端 未结 3 1842
孤独总比滥情好
孤独总比滥情好 2020-12-09 06:05

I am trying to update a row in an Azure table based on an Azure Function. I see that the Table bindings can handle an ICollector which has an Add method which will add a row

3条回答
  •  鱼传尺愫
    2020-12-09 06:42

    With today's bindings, you can set an ETag property to the value * to do an upsert:

    [FunctionName("Function1")]
    public static async Task Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log,
        [Table("test")] IAsyncCollector table)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string name = req.Query["name"];
        if (name == null)
            return new BadRequestResult();
    
        await table.AddAsync(new PocoClass { Name = name });
        return new OkObjectResult($"Hello, {name}");
    }
    
    public sealed class PocoClass
    {
        public string PartitionKey { get; } = "partition";
        public string RowKey { get; } = "row";
        public string ETag { get; } = "*";
        public string Name { get; set; }
    }
    

提交回复
热议问题