gpt4 book ai didi

Azure Function App无法将表绑定(bind)到类型 'Microsoft.WindowsAzure.Storage.Table.CloudTable'

转载 作者:行者123 更新时间:2023-12-02 22:57:24 27 4
gpt4 key购买 nike

我正在开发这个 Azure Function App,我只需要使用 GET 方法从 Azure 存储表中检索所有用户。当我运行我的应用程序时,出现错误:

无法将表绑定(bind)到类型“Microsoft.WindowsAzure.Storage.Table.CloudTable”。

这是我的代码:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Linq;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.AspNetCore.Builder;

namespace FunctionEncrypt
{
public class GetUser
{
[FunctionName("GetAll")]
public static async Task<IActionResult>
GetAll(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "users")] HttpRequest req,
[Table("user", Connection = "AzureWebJobsStorage")] CloudTable cloudTable,
ILogger log)
{
log.LogInformation("Getting All users");

TableQuery<UserTable>
query = new TableQuery<UserTable>();
var segment = await cloudTable.ExecuteQuerySegmentedAsync(query, null);
var data = segment.Select(UserExtensions.ToUser);

return new OkObjectResult(data);
}
}
}

这是我的引用文献: enter image description here

我已经研究了这个错误,我寻找的每个地方都说要替换“using Microsoft.WindowsAzure.Storage.Table;”对于“using Microsoft.Azure.Cosmos.Table;”,但即使在更改引用后,我仍然收到相同的错误消息。我还检查了版本,它们是正确的。当我更改宇宙引用时,我也更改了我的包引用。我删除了,因为我之前在多个引用方面遇到过问题。

有什么想法可能是错误的吗?

最佳答案

对于 net6.0 v4 请仅使用以下软件包:
Microsoft.Azure.WebJobs.Extensions.Tables

这意味着,如果您不使用 TableQueue 绑定(bind),则可以卸载 Microsoft.Azure.WebJobs.Extensions.Storage

最后,您必须清理代码。
删除使用:
使用 Microsoft.WindowsAzure.Storage.Table;

这也意味着 CloudTable 不再可用。
您必须使用 TableClient或绑定(bind) TableEntity

请在此处查找示例:
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Tables

using System.Linq;
using System.Threading.Tasks;
using Azure.Data.Tables;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;

namespace FunctionEncrypt
{
public class GetUser
{
[FunctionName("GetAll")]
public static async Task<IActionResult> GetAll(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "users")] HttpRequest req,
[Table("user", Connection = "AzureWebJobsStorage")] TableClient client,
ILogger log)
{
log.LogInformation("Getting All users");
var result = client.Query<Azure.Data.Tables.TableEntity>().ToList();
return new OkObjectResult(result);
}
}
}

关于Azure Function App无法将表绑定(bind)到类型 'Microsoft.WindowsAzure.Storage.Table.CloudTable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73358160/

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