Jason Rowe

Be curious! Choose your own adventure.

Odata Osht! and some examples

 

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)

 

http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear le 1989 and ReleaseYear ge 1980 and AverageRating gt 4&$expand=Awards

 

(from t in Titles.Expand("Awards")
where t.ReleaseYear < 1989 && t.ReleaseYear > 1980 && t.AverageRating > 4
select t)

 

http://odata.netflix.com/Catalog/Titles?$filter=Type eq ‘Movie’ and Instant/Available eq true and (Rating eq ‘G’ or Rating eq ‘PG-13’)

 

(from t in Titles
where t.Type == "Movie" && t.Instant.Available == true && 
   (t.Rating == "G" || t.Rating == "PG-13")
   select t)

 

http://odata.netflix.com/Catalog/Titles?$filter=Type eq ‘Movie’ and Instant/Available eq true and (Rating ne ‘R’ and Rating ne ‘NC-17’ and Rating ne ‘UR’ and Rating ne ‘NR’)

 

(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)

 

http://odata.netflix.com/Catalog/People?$filter=Name eq ‘James Cameron’&$expand=Awards,TitlesDirected

 

(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)

 

http://odata.netflix.com/Catalog/Languages(‘French’)/Titles?$filter=Type eq ‘Movie’ and Rating eq ‘UR’

 

(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();

http://odata.netflix.com/Catalog/Genres(‘Horror’)/Titles?$filter=ReleaseYear le 1979 and ReleaseYear ge 1970

 


(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)

http://odata.netflix.com/Catalog/Genres(‘Romantic Comedies’)/Titles?$filter=Type%20eq%20’Movie’ and round(AverageRating) ge 5&$orderby=year(Instant/AvailableFrom)

 

(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)


Posted

in

by

Comments

One response to “Odata Osht! and some examples”

  1. Chris Woodruff Avatar

    Glad my blog post helped. The OData team is trying to find a way to get OData to be fully LINQable. :-)

    Woody

Leave a Reply

Your email address will not be published. Required fields are marked *