不支持的错误

本文关键字:错误 不支持 | 更新日期: 2023-09-27 17:58:28

我有一个方法,它接受日期dtSince和字符串component作为参数。我需要编写一个单行linq查询,用于搜索在dtSince之前出现并且属于组件component的条目(如果指定)。我尝试过以下几种:

var result = from items in MyAzureTable
             where items.Occured >= dtSince
             && items.Component == (component ?? items.Component)
             select items;

但是我得到了一个NotSupported错误。我想items.Component == (component ?? items.Component)就是问题所在。

如前所述,component可以为null或为空。但我不能在原始查询中排除这一点,因为这是:

var result = from items in MyAzureTable
             where items.Occured >= dtSince
             select items;

可能返回1000多行(这似乎是Azure表的默认限制),因此我以后无法使用component进行筛选。如果我做了下面这样的事情,我可能要查找的条目位于第1001行。因此,它不会给我想要的结果。

if (!String.IsNullOrEmpty(component))
{
    result = result.Where(x => x.Component == component).ToList<>();
}

问题:在where子句中使用非空字符串之前,是否可以使用单行linq查询先检查非空字符串?

不支持的错误

试试这个:

var result = from items in MyAzureTable
             where items.Occured >= dtSince && 
                   (component == null || items.Component == component)
             select items;