Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function input binding: Which NuGet package for "Table" attribute?

I am creating a new azure function using HttpTrigger. I want to implement an azure table storage table as input binding. Following a source code example in msdn, I am not able to figure out in which NuGet package the "Table" attribute can be found.

Compile issue:

The type or namespace 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?)

Line of code, causing the issue:

public static async Task<IActionResult>
         Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, 
         [Table("AzureWebJobsHostLogscommon")] CloudTable cloudTable, 
         ILogger log)

The source code examples in MSDN I am refering to can be found here:

https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/azure-functions/functions-bindings-storage-table.md#input---c-example---one-

and here:

https://learn.microsoft.com/de-de/azure/azure-functions/functions-bindings-storage-table#input---c-example---cloudtable

The second example also shows the using directives. But even when copying the example the table-attribute cannot be resolved properly.

I have also seen this stackoverflow thread:

input-binding to table storage with an http-triggered function

but the first solution is only a workaround for me, as the table-storage connection is done during execution of the function and not as input binding. If you see the second proposed solution, it shows same code as in MSDN.

Here is my code:

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

namespace TableStorageIntegration.HTTPTrigger
{
    public static class Function1
    {
        [FunctionName("DoSomething")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,      
            [Table("AzureWebJobsHostLogscommon")] CloudTable cloudTable,
            ILogger log)
        {
            string someHttpGetParameter = req.Query["someParameter"];
            // .... 
            // Some addition code to be executed here but not relevant for the issue
            // .....
            return new OkObjectResult($"Data provided");
        }
    }
}

Is the proposed implementation still valid? And if yes, which NuGet package do I have to install to resolve the table attribute?

like image 763
rekcul Avatar asked Jan 26 '23 21:01

rekcul


2 Answers

You need to add this NuGet Package: https://nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage

like image 107
silent Avatar answered Jan 28 '23 11:01

silent


So seems like they have removed TableAttribute for some reason.

However they are working on bringing it back early 2022.

In the meantime, there are a couple of workarounds if you are using Azure Tables:

  • Remain on the v4 version of the Functions Extensions which has support for Tables until the new extension is released
  • Directly interact with the Azure Tables service from the Azure Function code by using the Azure.Data.Tables library linked above.
like image 20
Igor Meszaros Avatar answered Jan 28 '23 10:01

Igor Meszaros