English 中文(简体)
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
问题回答

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





相关问题
IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....

linq query for tag system - search for multiple tags

I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

How to filter duplicate list items

i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...

C# Grouping/Sorting a Generic List<> using LINQ

Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...

热门标签