我設立了堆棧溢出OData源作爲精彩文章Using LINQPad to Query Stack Overflow概述鏈接集合的計數和我想要做的事,如:獲取使用的OData和LINQ
Users.Where(x=>x.Badges.Count==0).Take(5)
得到網友認爲沒有徽章(「Badges? We don't need no stinkin' badges!」)。我得到一個DataServiceQueryException:
我設立了堆棧溢出OData源作爲精彩文章Using LINQPad to Query Stack Overflow概述鏈接集合的計數和我想要做的事,如:獲取使用的OData和LINQ
Users.Where(x=>x.Badges.Count==0).Take(5)
得到網友認爲沒有徽章(「Badges? We don't need no stinkin' badges!」)。我得到一個DataServiceQueryException:
不幸的是,OData不支持聚合函數 - 它僅支持有限的一組查詢函數described here。
骨料運營
所有聚合操作是不受支持的針對化DataServiceQuery, 包括:
Aggregate Average Count LongCount Max Min Sum
聚合操作必須或者在客戶端上執行,或者是 由服務操作包封。
希望微軟將在未來增強OData客戶端 - 令人沮喪的是(看起來)擁有LINQ的所有能力,然後無法使用它。
看起來像徽章沒有Count屬性。這就是發生異常的原因。
<EntityType Name="Badge">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property xmlns:p8="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="Id" Type="Edm.Int32" Nullable="false" p8:StoreGeneratedPattern="Identity" />
<Property Name="UserId" Type="Edm.Int32" Nullable="true" />
<Property Name="Name" Type="Edm.String" Nullable="true" MaxLength="50" Unicode="true" FixedLength="false" />
<Property Name="Date" Type="Edm.DateTime" Nullable="true" />
<NavigationProperty Name="User" Relationship="MetaModel.BadgeUser" FromRole="Badge" ToRole="User" />
</EntityType>
可能您需要處理每個用戶以檢查徽章導航屬性是否解析爲任何內容。
目前不支持在導航屬性中實體的數量過濾(正如上面的Joe Albahari所指出的那樣)。在最新的CTP中,OData支持任何和所有可以過濾「空」導航屬性的功能。
參見
http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data-services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx to get the latest CTP.
這裏是任何/所有特徵的討論:
http://www.odata.org/blog/even-more-any-and-all
我開發[AdaptiveLINQ](http://www.adaptivelinq.com):一個組件,可以幫助您將彙總公開爲OData Feed – nlips
OData現在支持聚合函數:http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/odata-data-aggregation-ext-v4 .0.html – Kristopher