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

标签 c# linq azure azure-table-storage

我正在尝试处理在添加新属性之前插入 Azure 表存储的记录。 LINQ support is limited我正在努力让它发挥作用。

如何使用 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

}

一些无效的候选过滤器

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

最佳答案

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

关于c# - 如何从Azure存储表中选择缺少字段的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41259360/

相关文章:

c# - Team Foundation Server 是将 .net 网站自动发布到远程服务器的正确解决方案吗?

linq - WCF 数据服务、DTO 和 Entity Framework : The argument to DbIsNullExpression must refer to a primitive, 枚举或引用类型

c# - 为什么 float 和 int 具有如此不同的最大值,即使它们的位数相同?

c# - 我可以使用更通用的接口(interface)来简化我的类以使用命令模式吗?

c# - 我应该使用哪种设计模式来动态地为对象提供不同的效果?

linq - 学习 LinqToSql 还是坚持使用 ADO.NET?

c# - 连接两个字典

azure - 在 .Net Core Function Orchestrator 中调用 JavaScript Azure Function 作为事件函数

Azure Maps 静态图像服务 API 问题,来自数据上传 API 的 "invalid format"

java - 如何使用 azure java sdk 列出自定义镜像(从 ARM VM 捕获)