如何从Azure存储表中选择缺少字段的记录?

Ste*_*cke 10 c# linq azure azure-table-storage

我正在尝试处理在添加新属性之前插入Azure表存储的记录.在LINQ的支持是有限的,我努力得到这个工作.

如何使用LINQ(或其他方法)过滤Azure表以仅记录缺少给定实体的属性?

示例代码

我在Azure函数中编写它,并且在尝试字段的默认值时,此处的行计数返回0.

#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

}
Run Code Online (Sandbox Code Playgroud)

一些候选过滤器不起作用

  • r.Category is nothing 生成编译错误
  • String.IsNullOrEmpty(r.Category) 返回它不受支持
  • r.Category == null 返回错误的请求
  • !r.Category.HasValue 生成编译错误,因为它是一个字符串

Dog*_*lan 5

如果该属性在写入表存储时不存在于实体上,则该列将不存在于表上,因此您在查询中进行的任何比较(包括使用空字符串进行的比较)都会失败,并且您将得到一个空响应。