提问者:小点点

在v2 Azure函数中使用带有partitionKey和rowKey筛选器的CloudTable绑定到表存储


我正在使用Azure函数V2(.NET core 2.1)这篇文章解释了在V2 Azure函数中绑定表存储

但我想要的是提供过滤器条件以及[Table]属性。

例如,在下面的示例中,我希望只获取“partitionKey”为{partitionKey}且RowKey为{RowKey}的记录,其中{partitionKey}和{RowKey}属于路由。

[FunctionName("Function2")]
    public static async Task<IActionResult> GetPerson(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "api/person/{partitionKey}/{rowKey}")] HttpRequest req
            , string partitionKey
            , string rowKey
            , ILogger log
            , [Table("Test", "{partitionKey}",{rowKey} , Connection = "MyConnection")]CloudTable cloudTable
            )
    {
       //I am expecting only records with specified partitionKey and rowKey but its fetching all records like 'select * from Test' 
       var querySegment = cloudTable.ExecuteQuerySegmentedAsync(new TableQuery<MyEntity>(), null);
        foreach (var item in querySegment.Result)
        {
            log.LogInformation($"{item.PartitionKey} - {item.RowKey} - {item.Name}");
        }

应为:CloudTable应仅包含具有指定partitionKey和rowKey的一行实际CloudTable包含所有记录

我正在寻找类似于cosmosdb绑定的东西

[FunctionName("TestFunction")]
    public static async Task Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "regos/{queryStringParameter}")]
        [CosmosDB(
            databaseName: "MyDb",
            collectionName: "Table",
            CreateIfNotExists = true,
            ConnectionStringSetting = "CosmosDBConnectionString",                
            SqlQuery = "SELECT * FROM Table t where t.Col = {queryStringParameter}")]
            IEnumerable<dynamic> list,

上面的代码在Azure FunctionsV2中非常适用

有什么线索吗?


共1个答案

匿名用户

尝试链接中提到的建议

了解有关表存储输入绑定支持的更多信息

null

[FunctionName("TestFunction")]
public static async Task Run(
    [QueueTrigger("test-queue")] string message,
    [Table("testTable")] CloudTable testTable)
{
    var querySegment = testTable.ExecuteQuerySegmentedAsync(new TableQuery<ResultEntity>(), null);
    foreach (ResultEntity item in querySegment.Result)
    {
        // Access table storage items here
    }
}