使用CloudTable和partitionKey和rowKey筛选器绑定到v2 Azure Functions中的表存储

时间:2019-03-11 07:02:39

标签: azure azure-storage azure-functions azure-functions-runtime

我正在使用Azure Functions V2(.Net core 2.1) This帖子解释了在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 Functions V2完美配合

任何指针?

1 个答案:

答案 0 :(得分:0)

尝试link

中提到的建议

详细了解表存储输入绑定支持以下article

[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
    }
}

请告知我们以上内容是否对您有帮助,或者您在此问题上需要进一步的帮助。