My head is spinning from looking at Odata tonight. I keep going back and forth on if this is the coolest thing in the world or just a way to browse data via the URI. Either way it’s fun. Below are my notes and examples showing some limitations and features of Odata.
The first area I had some misunderstandings was when working with collections. Take a look at this question on StackOverflow “use linq to query nested odata collection“. This pretty much sums up the issue I was stuck on for awhile. How do relationships work and how can I query collections. This blog post helped me start to understand how keys and collections work.
Then, I find this post and this collection of resources. Now, I’m back to being sold on oData. The ease of filtering data is amazing. Filters also support functions if needed. Thanks to this tip for pointing that out.
Here is a set of examples for the Odata Netflix feed. I’ve listed the URI with the corresponding C# expression below.
http://odata.netflix.com/Catalog/Titles?$filter=Name eq ‘The Name of The Rose’
(from t in Titles where t.Name == "The Name of The Rose" select t)
http://odata.netflix.com/Catalog/Titles?$filter=AverageRating lt 2 and Instant/Available eq true
(from t in Titles where t.AverageRating < 2 && t.Instant.Available == true select t)
(from t in Titles.Expand("Awards") where t.ReleaseYear < 1989 && t.ReleaseYear > 1980 && t.AverageRating > 4 select t)
(from t in Titles where t.Type == "Movie" && t.Instant.Available == true && (t.Rating == "G" || t.Rating == "PG-13") select t)
(from t in Titles where t.Type == "Movie" && t.Instant.Available == true && (t.Rating != "R" && t.Rating != "NC-17" && t.Rating != "UR" && t.Rating != "NR") select t)
(from p in People.Expand("Awards").Expand("TitlesDirected") where p.Name == "James Cameron" select p)
http://odata.netflix.com/Catalog/Languages(‘Japanese’)/Titles?$filter=Type eq ‘Movie’”
(from l in Languages from t in l.Titles where l.Name == "Japanese" && t.Type == "Movie" select t)
(from l in Languages from t in l.Titles where l.Name == "French" && t.Type == "Movie" && t.Rating == "UR" select t)
http://odata.netflix.com/Catalog/Genres(‘Horror’)/Titles/$count?$filter=Type eq ‘Movie’
(from g in Genres from t in g.Titles where g.Name == "Horror" && t.Type == "Movie" select t).Count();
(from g in Genres from t in g.Titles where g.Name == "Horror" && t.ReleaseYear < 1979 && t.ReleaseYear > 1970 select t)
http://odata.netflix.com/Catalog/Titles(‘BVIuO’))
(from t in Titles where t.Id == "BVIuO" select t)
(from g in Genres from t in g.Titles where g.Name == "Romantic Comedies" && t.Type == "Movie" && Math.Round(t.AverageRating.Value) > 5 orderby t.Instant.AvailableFrom select t)
Leave a Reply