I have a wcf dataservice I am calling from Silverlight and I am expanding a collection property on an entity and I want to be able to sort the items in the expanded property by specifying it in the query.
Is there a way to do this?
here is the expand linq : - I want the Videos collection to be sorted by a property called SortOrder on the Video ent开发者_Python百科ity.
var expandQuery = (from s in dataService.Series.Expand("Videos")
where s.SeriesGUID == series.SeriesGUID
select s) as DataServiceQuery<Series>;
thanks Michael
This is currently not possible in the OData protocol as the $orderby query option only applies to the "root" of the query (in your case the Series entities). You could sort the results on the client to workaround this. Or if you really need to perform the sort on the server, you could define a service operation for this specific query.
Or, if you don't need to return the Series instance from the query as well, you could issue a query like /Series(guid'...')/Videos?$orderby=SortOrder which would work. To do this in the LINQ it would look like this:
var query = (from s in dataService.Series
where s.SeriesGUID == series.SeriesGUID
select s.Videos).OrderBy(v => v.SortOrder) as DataServiceQuery<Video>;
精彩评论