开发者

Use LINQ to query nested OData collection

开发者 https://www.devze.com 2022-12-27 19:28 出处:网络
I\'m playing around with the new Netflix OData feed (http://odata.netflix.com/Cata开发者_如何学JAVAlog/) and having some issues.I\'m trying to learn LINQ at the same time but having difficulty doing w

I'm playing around with the new Netflix OData feed (http://odata.netflix.com/Cata开发者_如何学JAVAlog/) and having some issues. I'm trying to learn LINQ at the same time but having difficulty doing what I thought was going to be quite simple.

I'd like to return a list of Titles that match a given Genre. The Titles object contains a collection of Genres. I'm not sure how to write this query. My attempt below does not appear to work using LINQPad.

from t in Titles
where t.Genres.Name.Contains("ABC")
select t


I was able to get my results using the LINQ:

from g in Genres
from t in g.Titles
where g.Name == "Horror"
select t

This way I don't need to use Expand. I can also use the URL: http://odata.netflix.com/Catalog/Genres('Horror')/Titles() to get the same results. This post by Chris Woodruff helped me understand the issue.


If you are receiving an DataServiceQueryException along with the message: Request version '1.0' is too low for the response. The lowest supported version is '2.0'.

You need to upgrade your version of .Net to .Net Framework 4 and download LINQPad for .NET Framework 4.0


Kyle, This will get you a listing of all movies by Genre

(from g in Genres.Expand("Titles")
where g.Name == "Horror"
select g).Dump();

This creates the following URL in LinqPad

/Catalog/Genres('Horror')?$expand=Titles

Its interesting that I needed to use the .Expand syntax to get it. When I browse to the netflix odata feed with my browser and want the same data I can get it with the following URL: http://netflix.cloudapp.net/Catalog/Genres('Horror')/Titles

There must be a way to get at it without .Expand

0

精彩评论

暂无评论...
验证码 换一张
取 消