views:

17

answers:

1

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 entity.

var expandQuery = (from s in dataService.Series.Expand("Videos")
where s.SeriesGUID == series.SeriesGUID
select s) as DataServiceQuery<Series>;

thanks Michael

A: 

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>; 
Vitek Karas MSFT
Can I add the Videos returned by your linq query to the Series already loaded on the client - sort of like a manual expand. I am databinding a listbox to the videos property on the currently selected series and really would like to be able to keep the vidoes in the series instance if possible.
MIantosca
If the Videos is a DataServiceCollection instances, you should be able to use its Load method to load it from DataServiceQuery.
Vitek Karas MSFT
Vitek, I am trying to implement your query example above but I am getting an error on the v variable - it is telling me v does not have a SortOrder property - it looks like v is a DataServiceCollection<Video> - not Video
MIantosca
I tried to adjust the query to return the DataServiceCollection<Video> but it it selling me that my linq qeury cannot be translated to uri.
MIantosca
var videoquery = (from s in dataService.Series where s.SeriesGUID == series.SeriesGUID select s.Videos) as DataServiceQuery<Video>;
MIantosca