gpt4 book ai didi

c# - 用于更新表存储实体的 Azure 函数 - 未找到 CloudTable.Execute

转载 作者:行者123 更新时间:2023-12-01 22:55:56 26 4
gpt4 key购买 nike

我开始使用 Azure 和 c#,并尝试使用表存储 - 并使用 Azure 函数来更新表中的实体。我的代码如下:

 #r "Microsoft.WindowsAzure.Storage"
#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;

public static async Task<HttpResponseMessage> Run(HttpRequest req, CloudTable lookupTable)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string partitionKey = data.Society;
string rowKey = data.ConnectionDetails.Environment;
string newConnection = data.ConnectionDetails.Connection;

TableOperation operation = TableOperation.Retrieve<SocietyConnectionDetails>(partitionKey, rowKey);
TableResult result = lookupTable.Execute(operation);
SocietyConnectionDetails societyConnectionDetails = (SocietyConnectionDetails)result.Result;

societyConnectionDetails.Connection = newConnection;
operation = TableOperation.Replace(societyConnectionDetails);
lookupTable.Execute(operation);
}

public class SocietyConnectionDetails : TableEntity
{
public string Connection {get; set;}
}

但是我得到的错误如下:

2020-02-25T10:33:16.956 [Error] run.csx(17,38): error CS1061: 'CloudTable' does not contain a definition for 'Execute' and no accessible extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
2020-02-25T10:33:16.984 [Error] run.csx(22,17): error CS1061: 'CloudTable' does not contain a definition for 'Execute' and no accessible extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
2020-02-25T10:33:17.011 [Error] run.csx(8,47): error CS0161: 'Run(HttpRequest, CloudTable)': not all code paths return a value

我可以看到,当我尝试“执行”我的表操作时,问题就发生了...这可能是一个相对简单的问题,但我正在努力找出为什么这不起作用...

感谢您的帮助..

最佳答案

我可以重现您的错误。

像这样:

enter image description here

解决方案是将 function.proj 文件添加到您的函数中。 enter image description here

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>
</Project>

然后错误就会消失。(如果不这样做,编译步骤将不会成功。) enter image description here

关于c# - 用于更新表存储实体的 Azure 函数 - 未找到 CloudTable.Execute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60392713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com