gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:12:46 25 4
gpt4 key购买 nike

我正在尝试处理在添加新属性之前插入 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com