使用 LINQ to Netflix OData 按演员请求所有影片
我正在尝试使用 LINQPad 来使用 LINQ 查询 Netflix OData。我正在尝试搜索具有特定演员的所有电影。例如:
from t in Titles
from p in t.Cast
where p.Name == "Morgan Freeman"
select t.Name
这会导致:
NotSupportedException:只能投影正在翻译的查询中的最后一个实体类型
我也尝试过:
from p in People
from t in p.TitlesActedIn
where p.Name == "Morgan Freeman"
select t.Name
这会导致以下错误:
NotSupportedException:不支持“选择”方法
我尝试了一些其他方法,例如在 where 子句中使用 Id,并选择不同的内容,但无济于事。
I'm experimenting with LINQPad to use LINQ to query the Netflix OData. I'm trying to search for all films with a particular actor in. For example:
from t in Titles
from p in t.Cast
where p.Name == "Morgan Freeman"
select t.Name
this results in:
NotSupportedException: Can only project the last entity type in the query being translated
I also tried:
from p in People
from t in p.TitlesActedIn
where p.Name == "Morgan Freeman"
select t.Name
which results in the following error:
NotSupportedException: The method 'Select' is not supported
I've tried a few other approaches, such as using Id's in the where clause, and selecting different things, but have got nowhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行以下任一操作:
但请注意,这要求您不指定 Id,这将转换为:
/People(190)/TitlesActedIn?$select=Name
如果您需要根据非关键属性进行过滤,则需要执行以下操作:
这将转换为:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn
您也可以只询问这些标题的名称,但由于属性的类型,LinqPad 似乎没有办法做到这一点它产生。它看起来像:
这将翻译为:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn&$select=TitlesActedIn/Name
谢谢,
维泰克·卡拉斯 [MSFT]
You can do either this:
But note that this requires you not specify the Id, this translates to:
/People(190)/TitlesActedIn?$select=Name
If you need to filter based on non-key properties, you need to do something like:
This translates to:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn
You could also just ask for the names of those titles, but LinqPad doesn't seem to have a way to do that, due to the type of properties it generates. It would look like:
Which would translate to:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn&$select=TitlesActedIn/Name
Thanks,
Vitek Karas [MSFT]