Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select records where field is missing from an Azure Storage Table?

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
like image 761
Steph Locke Avatar asked Dec 21 '16 09:12

Steph Locke


1 Answers

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.

like image 87
Dogu Arslan Avatar answered Oct 05 '22 23:10

Dogu Arslan