2011-06-07 110 views
2

我有一个方法接受日期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可以为空或空。但我不能排除在原始查询,因为这:

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

可能返回超过1000行(这似乎是天青表的默认限制),因此我无法与component后过滤。如果我做了类似下面的事情,我可能要查找的条目在第1001行。因此,它不会给我我要找的结果。

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

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

+0

蔚蓝是否真的不提供IQueryable的'' API?我期望'在哪里“构成”... – 2011-06-07 06:50:02

+0

@Marc,Azure表中似乎存在可查询行的限制。这家伙正试图查询2亿,并看看发生了什么事。 ;)http://stackoverflow.com/questions/5837213/azure-querying-200-million-entities – 2011-06-07 06:52:11

+0

@Alex - 但那是不同的;通过* composing *一个查询你应该过滤*在查询进入服务器之前,所以最终查询不会(或不应该)执行打开的查询 – 2011-06-07 07:39:11

回答

1

试试这个:

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

感谢它的工作。 – 2011-06-07 06:54:02