2
votes

I am using Azure Functions V2 ( .Net core 2.1 ) This post explains Binding Table Storage in V2 Azure Function

But what I am looking for is provide Filter condition along with the [Table] attribute.

e.g. In below example I would like to fetch only records whose 'PartitionKey' is {partitionKey} and RowKey is {rowKey} , where {partitionKey} and {rowKey} belongs to routes.

[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}");
        }

Expected : cloudTable should contain only one row with specified partitionKey and rowKey Actual cloudTable contains all the records

I am looking for something like CosmosDb binding

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

Above code workds perfectly fine with the Azure Functions V2

any pointers?

1

1 Answers

-1
votes

Try the suggestions mentioned in the link

Learn more on Table storage input binding supports the following 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
    }
}

Kindly let us know if the above helps or you need further assistance on this issue.