不支持错误
我有一个接受日期 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: