10
votes

I'm attempting to process records that were inserted into Azure Table Storage prior to the addition of a new attribute. The LINQ support is limited and I'm struggling to get this to work.

How would one use LINQ (or another method) to filter an Azure Table to just records missing an attribute for a given entity?

Sample Code

I'm writing it in an Azure Function, and the row count here returns 0, when attempting a default value for the field.

#r "Microsoft.WindowsAzure.Storage"

using System.Net;
using Microsoft.WindowsAzure.Storage.Table;

public static HttpResponseMessage Run(HttpRequestMessage req, IQueryable<ts_webhit> inTable, TraceWriter log)
{
    IEnumerable<ts_webhit> recs = (from r in inTable
                                   where "2016-11-21 12:45" == r.PartitionKey
                                   &&    ""                 == r.Category  //The filter I need to run
                                   select r);
    log.Info($"{recs.Count()}");
    return req.CreateResponse(HttpStatusCode.OK, recs.ToList());
}

public class ts_webhit : TableEntity
{

    public string Category { get; set; } = ""; //Attempting a default value

}

Some candidate filters that didn't work

  • r.Category is nothing generates a compilation error
  • String.IsNullOrEmpty(r.Category) returns that it's not supported
  • r.Category == null returns a bad request
  • !r.Category.HasValue generates a compilation error as it's a string
1
Looks like there's a prior question, tho (IMO) lower quality! stackoverflow.com/questions/20913668/…Steph Locke

1 Answers

5
votes

If the property did not exist on the entity when it was written to table storage than that column will not exist on the table hence any comparison you make in your query - including the comparison with an empty string - will fail and you will get an empty response.