2011-02-18 32 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