不支持错误

发布于 2024-11-13 12:46:31 字数 1034 浏览 3 评论 0原文

我有一个接受日期 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 或为空。但我无法在原始查询中排除这一点,因为 this:

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

可能会返回超过 1000 行(这似乎是 Azure 表的默认限制),因此我稍后无法使用 组件 对其进行过滤。如果我执行如下操作,我可能要查找的条目位于第 1001 行。因此,它不会给出我正在查找的结果。

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

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

I have a method that accepts a date dtSince and a string component as parameters. I need to write an one-line linq query that searches for entries that occurred before dtSince and is of Component component (if specified). I have tried the following:

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

But I'm getting a NotSupported error. I guess the items.Component == (component ?? items.Component) is the problem.

As mentioned, component can be null or empty. But I cannot exclude that in the original query, because this:

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

might return more than 1000 rows (which appears to be the default limit of Azure tables) and therefore I cannot filter it with the component later. If I do something like the below, the entry I might be looking for is at row 1001. Thus, it won't give me the result I am looking for.

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

Question: Is it possible to have a one line linq query that can check for a non-empty string first before using it in a where clause?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-11-20 12:46:31

试试这个:

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

Try this:

var result = from items in MyAzureTable
             where items.Occured >= dtSince && 
                   (component == null || items.Component == component)
             select items;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文