Use LINQ to query nested OData collection

Kyle Russell picture Kyle Russell · Apr 21, 2010 · Viewed 7.1k times · Source

I'm playing around with the new Netflix OData feed (http://odata.netflix.com/Catalog/) 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

Answer

Kyle Russell picture Kyle Russell · Apr 21, 2010

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.