2011-02-18 53 views
0

下面的查询,我在展开的导航性能,时刻表,它具有与AssociatedListing财产许多到1关系正常工作:过滤一个LINQ/OData的查询在1到许多导航属性

from la in ListingAssociations.Expand("AssociatedListing").Expand("AssociatedListing/Schedules") 
where la.ListingId==60 
select la 

在结果中,我可以看到对应于每个多个附表对象AssociatedListing对象。这很好。

然而,当我尝试在任何附表字段添加过滤器:

from la in ListingAssociations.Expand("AssociatedListing").Expand("AssociatedListing/Schedules") 
where la.ListingId==60 && la.AssociatedListing.Schedules.StartDate > DateTime.Today 
select la 

我得到的错误:

"'System.Collections.ObjectModel.Collection' does not contain a definition for 'StartDate' and no extension method 'StartDate' accepting a first argument of type 'System.Collections.ObjectModel.Collection' could be found...".

所以我想这个问题是起始日期时间表类的字段,而“时间表”的导航属性为收集时间表对象,因此Schedules.StartDate没有任何意义。但是,在这种情况下,必须有一些方法来指定过滤器。怎么样?

任何帮助将不胜感激!

回答

2

更改,其中来自该条款:

where la.ListingId==60 
    && la.AssociatedListing.Schedules.StartDate > DateTime.Today 

要这样:

where la.ListingId==60 
    && la.AssociatedListing.Schedules.All(x => x.StartDate > DateTime.Today) 

如果你想它,以便任何附表有一个起始日期大于今天(而不是过滤到所有人都可以进行的过滤),将All更改为Any

+0

不幸的是,Odata/WCF数据服务不支持Any和All。 – skeej 2011-02-18 13:38:07