Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use LINQ to query nested OData collection

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
like image 360
Kyle Russell Avatar asked Apr 20 '10 23:04

Kyle Russell


2 Answers

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.

like image 97
Kyle Russell Avatar answered Nov 05 '22 14:11

Kyle Russell


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

like image 23
Nicholas Murray Avatar answered Nov 05 '22 13:11

Nicholas Murray