Netflix OData with LINQ:方法'Select'不支持."

本文关键字:不支持 quot Select 方法 OData with LINQ Netflix | 更新日期: 2023-09-27 18:04:53

我正在使用以下代码查询Netflix目录:

NetflixCatalog cat = new NetflixCatalog(CatalogUri);
IQueryable<Title> query = from person in cat.People
                          from t in person.TitlesActedIn
                          where person.Name == searchString
                          orderby t.ReleaseYear
                          select new Title
                          {
                              Name = t.Name,
                              BoxArt = t.BoxArt,
                              Synopsis = t.Synopsis,
                              ReleaseYear = t.ReleaseYear,
                              Runtime = t.Runtime,
                              Type = t.Type,
                              Genres = t.Genres,
                              Cast = t.Cast
                          };
foreach (var title in query)
{
   ...
}

foreach行出现上述错误

Netflix OData with LINQ:方法'Select'不支持."

我想我可以给你一个有效的查询,但我无法解释为什么你的不工作(除非你对'因为它的OData和他们不支持每个Linq命令'感到满意)

尝试将您的查询更改为类似

的内容
NetflixCatalog cat = new NetflixCatalog(CatalogUri);
string searchString = "Michael Caine";
var person = (from r in cat.People where r.Name == searchString select r).Single();
var query  = (from p in cat.People 
              where p.Id == person.Id   
              from t in p.TitlesActedIn
              orderby t.ReleaseYear
              select new Title
                      {
                          Name = t.Name,
                          BoxArt = t.BoxArt,
                          Synopsis = t.Synopsis,
                          ReleaseYear = t.ReleaseYear,
                          Runtime = t.Runtime,
                          Type = t.Type,
                          Genres = t.Genres,
                          Cast = t.Cast
                      };

注意,这实际上是两个查询,但我不认为你可以将它们组合成一个查询。例如,你不能只改变

  where p.Id == persion.Id 

where p. name == searchString

现在,我不确定为什么,期望我已经了解到OData不像LinqToSQL(我更熟悉),我不应该期望它以类似的方式表现。

例如,使用linqpad浏览会出现一些奇怪的结果。

   (from r in People where r.Name == "Michael Caine" select r).Single()

返回
Id             13473 
Name           Michael Caine 
Awards         Collection<TitleAward> (0 items) 
TitlesActedIn  Collection<Title> (0 items) 
TitlesDirected Collection<Title> (0 items) 

让人觉得他好像从来没演过电影。但

(from r in People where r.Name == "Michael Caine" select  new { r.TitlesActedIn }    ).Single().Dump();

返回一个匿名类{TitlesActedIn = System.Collections.ObjectModel.Collection ' 1[LINQPad.User.]标题]}

包含91个标题。

(from r in People where r.Name == "Michael Caine" select   r.TitlesActedIn ).Single().Dump();

抛出错误:NotSupportedException:只能在上次导航后指定查询选项(order, where, take, skip)。