简体   繁体   English

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

[英]Azure Function to Update Table Storage entity - CloudTable.Execute not found

I'm starting out using Azure and c# and I'm attempting to use Table Storage - and using an Azure Function to update entitys in the table.我开始使用 Azure 和 c#,我正在尝试使用表存储 - 并使用 Azure 函数来更新表中的实体。 My code is as follows:我的代码如下:

 #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;}
}

But the errors im getting are as follows:但我得到的错误如下:

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

I can see that the issue is happening when im attempting to 'Execute' my Table Operations... this might be a relatively straight forward problem but I'm struggling to work out why this wouldn't be working...当我尝试“执行”我的表操作时,我可以看到问题正在发生……这可能是一个相对简单的问题,但我正在努力弄清楚为什么这不起作用……

Thanks for any help..谢谢你的帮助..

I assume you are using the Azure Functions runtime 2, and in this case the problem is related to your references.我假设您使用的是 Azure Functions 运行时 2,在这种情况下,问题与您的引用有关。 You should reference the nuget package Microsoft.Azure.WebJobs.Extensions.Storage and ensure it is installed in your function, according to this article in Microsoft's documentation.根据 Microsoft 文档中的这篇文章,您应该引用 nuget 包Microsoft.Azure.WebJobs.Extensions.Storage并确保它已安装在您的函数中。

I can reproduce your error.我可以重现你的错误。

Like this:像这样:

在此处输入图片说明

Solution is add a function.proj file to your function.解决方案是将 function.proj 文件添加到您的函数中。 在此处输入图片说明

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

Then the error should disappear.然后错误应该消失。 (If you dont do this. the compilation step will not success.) (如果不这样做,编译步骤将不会成功。) 在此处输入图片说明

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

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