带有 LINQ 的 Netflix OData:“方法‘Select’”不支持。”
我正在遵循一个(糟糕?)使用以下代码查询 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
行上崩溃并出现上述错误。
I'm following a (poor?) example of querying the Netflix catalog by using the following code:
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)
{
...
}
It's blowing up on the foreach
line with the above-mentioned error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我可以给你一个有效的查询,但我无法解释为什么你的查询不起作用(除非你对“因为它的 OData 并且它们不支持每个 Linq 命令”感到足够满意)
尝试将你的查询更改为注意
,这实际上是两个查询,但我认为您不能将它们合并为一个查询。例如你不能只更改
为
where p.Name == searchString
现在,我不确定为什么,期望我已经了解到 OData 与 LinqToSQL(我更熟悉)不同,并且我不应该期望它以类似的方式运行。
例如,使用 linqpad 浏览会出现一些奇怪的结果。
回归
这让他看起来好像从未出演过任何电影。
但
返回一个匿名类
{ TitlesActedIn = System.Collections.ObjectModel.Collection`1[LINQPad.User.Title] }
其中包含 91 个标题。
而
抛出错误:
NotSupportedException:只能在上次导航后指定查询选项(orderby、where、take、skip)。
希望这能有所帮助,而不是令人困惑。
I think I can give you a query that works, but I can't explain why yours doesn't work (unless you are happy enough with 'Becauses its OData and they don't support every Linq command')
Try changing your query to something like
Note, that this is effectively two queries, but I don't think you can combine them into one query. For example You can't just change
to
where p.Name == searchString
Now, I'm not sure exactly why, expect that I have learnt that OData is not anything like LinqToSQL (which I am more familar with) and I shouldn't expect it to behave in a similar way.
For example, using linqpad to browse does through up some strange results.
returns
which makes it look like he never acted in any films.
But
returns an anonymous class
{ TitlesActedIn = System.Collections.ObjectModel.Collection`1[LINQPad.User.Title] }
which contains 91 titles.
Whereas
throws an error :
NotSupportedException: Can only specify query options (orderby, where, take, skip) after last navigation.
Hope this helps more than it confuses.