question

adrianamalea-4040 avatar image
1 Vote"
adrianamalea-4040 asked LamLe-6503 commented

WindowsAzure.Storage vs. Azure.Data.Tables binding in a Http Trigger function

Hello,

Can you please explain me what is the correct way to use Storage libs in the context of deprecated / non-deprecated?

  1. If I am using

Microsoft.Azure.WebJobs.Extensions.Storage Version="4.0.4"
"Microsoft.NET.Sdk.Functions Version="3.0.13"

and the following code:

 using Microsoft.WindowsAzure.Storage.Table;
 [FunctionName("CalloutFunction")]
         public static async Task<HttpResponseMessage> Run(
             [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req,
             [DurableClientAttribute] IDurableOrchestrationClient client,
             [Table("ZPGCallouts")] Microsoft.WindowsAzure.Storage.Table.CloudTable cloudTable)

When starting the function, it throws:

Microsoft.Azure.WebJobs.Host: Error indexing method 'SubscriptionProvisioningCalloutFunction'. Microsoft.Azure.WebJobs.Extensions.Storage: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'

I don't have a CosmosDB in my project, so I am not confident that using Microsoft.Azure.Cosmos.Table instead of WindowsAzure.Storage.Table is the solution.

  1. I have tried with Azure.Data.Tables
    I have the following model entity that implements Azure.Data.Tables.ITableEntity, instead of inheriting from Microsoft.WindowsAzure.Storage.Table.TableEntity

    public class CalloutEntity : ITableEntity
    {
    public CalloutEntity() {}

           public CalloutEntity(CalloutData data)
             {
                 if (data == null) return;
                 Id = data.Id;
                 PartitionKey = "TestCallout";
                 RowKey = Guid.NewGuid().ToString("N");
                 Timestamp = DateTimeOffset.UtcNow;
             }
                   
             public Guid Id { get; set; }
             public string PartitionKey { get; set; }
             public string RowKey { get; set; }
             public DateTimeOffset? Timestamp { get; set; }
             public ETag ETag { get; set; }
         }
     }
    

and I also have a trigger function, that used to bind a Microsoft.WindowsAzure.Storage.Table.CloudTable (see code above at 1.)

Which class from which lib should I bind now? I can't use CosmosDB.CloudTable, because I am not using the ComosDB service.
I need a class that knows like CloudTable to use the connection string from AzureWebJobsStorage.

Thanks for the clarifications!




azure-functionsazure-table-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PramodValavala-MSFT avatar image
0 Votes"
PramodValavala-MSFT answered LamLe-6503 commented

@adrianamalea-4040 The Microsoft.Azure.Cosmos.Table SDK implements the Table API which both Azure Storage Tables and Azure CosmosDB Table API support. The SDK adapts based on the service connecting to. Therefore the Microsoft.Azure.WebJobs.Extensions.Storage SDK references Microsoft.Azure.Cosmos.Table instead.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you! That explains a lot!

0 Votes 0 ·

hYMkS5D.png

@PramodValavala-MSFT - Still, getting the same issue after adding Microsoft.Azure.Cosmos.Table to the .Net 6 Azure Functions v4 project.
Error: Attribute 'Table' is not valid on this declaration type. It is valid on 'type' declarations only.

0 Votes 0 ·
LamLe-6503 avatar image LamLe-6503 HariKrishna-6915 ·

What version of Microsoft.Azure.WebJobs.Extensions.Storage are you using, HariKrishna-6915?
I've run into the same problem as the author has. Referencing issue is the problem, actually.
My project is Net 6, Azure function v4. In csproj, it refers to Microsoft.Azure.WebJobs.Extensions.Storage v4.0.5. It is 4 because Table is missing from v5 (you can read more here)
And in the func, using Microsoft.Azure.Cosmos.Table; would work.

0 Votes 0 ·