Request Genres by MovieId using LINQ to Netflix OData?

Up vote 0 down vote favorite share g+ share fb share tw.

I am trying to create a LINQ query to return genres by movieid. The LINQ works in LINQPAD4. Can someone help me with the proper syntax?

I am getting the following errors: Cannot implicitly convert type 'System.Linq. IQueryable' to 'System.Linq. IQueryable'.

An explicit conversion exists (are you missing a cast? ) and Cannot implicitly convert type 'System.Collections.Generic. List' to 'System.Collections.Generic.

List' Code:(note I have wrapped Title in the following line with parenthesis, but are actually brackets in my code. Public List(Genre) GetGenresByMovieId(string movieid) { var genres = from t in MovieCatalog. Titles where t.

Id == "BVlLx" select t. Genres; return genres.ToList(); } linq odata netflix link|improve this question edited Oct 14 '10 at 3:47 asked Oct 14 '10 at 2:10obautista467113 100% accept rate.

The right query would look like public IEnumerable GetGenresByMovieId(string movieId) { return from title in ctx. Titles from genre in title. Genres where title.

Id == "BVlLx" select genre; } In the method call syntax, you need to use SelectMany, not Select, since the filter on titles returns a list of titles (which will always contain just one title, but the compiler doesn't know that) and so you want to "concatenate" all genres for each title in the results. The return type is actually IQueryable, but if you only plan to enumerate over it, you can use IEnumerable, or call ToList() to force execution right there in the method (the way I wrote it the query would actually execute only once you try to enumerate it).

Thank you. I am trying to bind the result set to a data control (i.e. Repeater).

Will this work: rpt. Datasource = GetGenresByMovieId("BVlLx"); rpt.DataBind(); I do not understand your comment about SelectMany. – obautista Oct 14 '10 at 17:04 Forgot to mention.

In markup page I want to display only the Genre Names for the Movie Title, so something like this: . I abbreviated the code a little. – obautista Oct 14 '10 at 17:31 Sorry I don't know enough about ASP.

NET to answer this question. The method simply returns enumeration of Genre objects. – Vitek Karas MSFT Oct 14 '10 at 21:58 If you use the syntax above, you don't have to care about SelectMany (that's what C# compiler translates the above code into).

– Vitek Karas MSFT Oct 14 '10 at 21:58.

Your problem is your projection: select new { Name = g. Name } That is projecting the query into an anonymous type. You need to project into the IQueryable you have declared (IQueryable) When working with LINQ queries, it's preferable to use implicitly-typed variables (var).

Also, not sure why you have that extra "from" in your query, you don't need that. Something like this should work: var genres = from t in MovieCatalog. Titles where t.

Id = "BVlLx" select t. Genres; return genres.ToList(); var genres should be typed to an IQueryable. That is assuming you want to return a collection of Genre objects.

If you just want the name, do this: select t.Genres. Name But that will return a collection of string objects (and var genres should be typed to an IQueryable). However, I have no idea about the NetFlix OData API, but that should get you on the right track.

Thanks. I am not getting this error: Cannot implicitly convert type 'System.Collections.Generic. List>' to 'System.Collections.Generic.

List' – obautista Oct 14 '10 at 3:08 @obautista - because of your method signature (you expect a return type of List). What do you want returned? A collection of Genres, or a collection of Genre names?

– RPM1984 Oct 14 '10 at 3:11 I realized that after I posted. I edited my post to reflect using List. I tried the LINQ suggested in LINQPAD4 and that returns "The method 'Select' is not supported".

This may be the reason for the anonymous type. My last comment reflects using List. – obautista Oct 14 '10 at 3:18 @obautista - can you edit your question to show what code you currently have?

Im not too concerned with LinqPad right now, just with your LINQ code. When I said "if you just want the name, do this..", I meant INSTEAD of the select t. Genres, not on it's own.

That's why you go the LinqPad error. – RPM1984 Oct 14 '10 at 3:33 This generates the error above: public List GetGenresByMovieId(string movieid) { var genres = from t in MovieCatalog. Titles where t.

Id == "BVlLx" select t. Genres; return genres.ToList(); } – obautista Oct 14 '10 at 3:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions