1

I am writing my first Azure Function and Azure table code. I am getting issue when I write Get query function. I have the following code that would try to get all the jobs from the table.

public static class GetJobStatus
{
    [FunctionName("GetJobStatus")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
        [Table("JobTable")] CloudTable jobTable,
        ILogger log)
    {
        log.LogInformation("Get job status.");

        string jobId = req.Query["jobid"];

        TableQuery<JobTable> query = new TableQuery<JobTable>();
        var segment = await jobTable.ExecuteQuerySegmentedAsync(query, null);
        var data = segment.Select(JobExtension.ToJob);

        return new OkObjectResult("");
    }
}

But, I get compile time errors on these statements:

TableQuery<JobTable> query = new TableQuery<JobTable>();
var segment = await jobTable.ExecuteQuerySegmentedAsync(query, null);

I am trying to paste the actual error messages that appear on hover: enter image description here and, get the following on the ExecuteQuerySegmentedAsync method enter image description here

My JobTable inherits from ITableEntity (Azure.Data.Tables):

public class JobTable : ITableEntity
{
    public string Id { get; set; }
    public DateTime CreatedTime { get; set; }
    public JobRequest Request { get; set; }

    //ITableEntity Members
    public virtual string PartitionKey { get; set; } = "Job";
    public virtual string RowKey { get => Id; set => Id = value; }
    public DateTimeOffset? Timestamp { get; set; }
    public ETag ETag { get; set; }
}

I have the following nuget packages installed: enter image description here

I was trying to implement from this article, but it uses older nuget packages, and I was getting trouble.

Update #1:

As per the suggestions from Gaurav Mantri, to be consistent, I have removed Azure.Data.Tables and started using Microsoft.WindowsAzure.Storage.Table. That fixed the compile time errors. But now I get the following runtime error:

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

Update #2:

I couldn't make it work, so I reverted all my code and references to use Microsoft.Azure.Cosmos.Table as described in the article I was referncing. Everything works as expected now. But, I still would like to see how I can use the newer libraries. For the original issue that was receiving, it was solved by Gaurav's suggestion so I will accept the answer for now.

Sri Reddy
  • 6,832
  • 20
  • 70
  • 112

1 Answers1

2

I believe you are running into this issue is because you are using two different SDKs - Azure.Data.Tables and Microsoft.WindowsAzure.Storage.Table.

Your JobTable entity implements ITableEntity from Azure.Data.Tables and you are using that with your CloudTable from Microsoft.WindowsAzure.Storage.Table.

Can you try by removing Azure.Data.Tables package and just use Microsoft.WindowsAzure.Storage.Table?

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Great catch. I removed `Azure.Data.Tables` package and also updated `JobTable` to use `Microsoft.WindowsAzure.Storage.Table` and but `JobTable` entity now inherits from `TableEntity`. The code compiles but gives a runtime error: `The 'GetJobStatus' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'GetJobStatus'. Microsoft.Azure.WebJobs.Extensions.Tables: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.` – Sri Reddy Mar 03 '22 at 20:22
  • You can try to do it the other way around i.e. use Azure.Data.Tables. Essentially the idea is to use just one SDK. – Gaurav Mantri Mar 03 '22 at 20:53
  • When I try to do the other way, I can't use `CloudTable` and `TableQuery` anymore. I think I have to use `TableClient` instead. I don't see any examples of how to use `TableClient` in my code specially Azure Functions. Appreciate any leads. – Sri Reddy Mar 03 '22 at 21:24