【问题标题】:Binding to Table Storage in v2 Azure Functions using CloudTable with partitionKey and rowKey Filter使用 CloudTable 与 partitionKey 和 rowKey 筛选器绑定到 v2 Azure Functions 中的表存储
【发布时间】:2019-03-11 07:02:39
【问题描述】:

我正在使用 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 完美配合

任何指针?

【问题讨论】:

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


    【解决方案1】:

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

    如果以上内容有帮助,或者您在此问题上需要进一步帮助,请告诉我们。

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      • 2012-08-11
      • 2016-07-27
      相关资源
      最近更新 更多