使用 LINQ to Netflix OData 按演员请求所有影片

发布于 2024-09-03 20:26:57 字数 546 浏览 13 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-09-10 20:26:57

您可以执行以下任一操作:

from p in People
where p.Id == 190
from t in p.TitlesActedIn
select new { Name = t.Name }

但请注意,这要求您不指定 Id,这将转换为:
/People(190)/TitlesActedIn?$select=Name

如果您需要根据非关键属性进行过滤,则需要执行以下操作:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn
}

这将转换为:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn

您也可以只询问这些标题的名称,但由于属性的类型,LinqPad 似乎没有办法做到这一点它产生。它看起来像:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn.Select(t => new Title { Name = t.Name })
}

这将翻译为:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn&$select=TitlesActedIn/Name

谢谢,
维泰克·卡拉斯 [MSFT]

You can do either this:

from p in People
where p.Id == 190
from t in p.TitlesActedIn
select new { Name = t.Name }

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:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn
}

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:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn.Select(t => new Title { Name = t.Name })
}

Which would translate to:
/People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn&$select=TitlesActedIn/Name

Thanks,
Vitek Karas [MSFT]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文