使用 LINQ 查询嵌套 OData 集合

发布于 2024-08-30 03:55:36 字数 486 浏览 3 评论 0原文

我正在尝试新的 Netflix OData feed (http://odata.netflix.com/Catalog/)并遇到一些问题。我正在尝试同时学习 LINQ,但在做我认为非常简单的事情时遇到困难。

我想返回与给定类型匹配的标题列表。 Titles 对象包含 Genres 的集合。我不知道如何编写这个查询。我的以下尝试似乎无法使用 LINQPad 进行。

from t in Titles
where t.Genres.Name.Contains("ABC")
select t

I'm playing around with the new Netflix OData feed (http://odata.netflix.com/Catalog/) and having some issues. I'm trying to learn LINQ at the same time but having difficulty doing what I thought was going to be quite simple.

I'd like to return a list of Titles that match a given Genre. The Titles object contains a collection of Genres. I'm not sure how to write this query. My attempt below does not appear to work using LINQPad.

from t in Titles
where t.Genres.Name.Contains("ABC")
select t

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

过期以后 2024-09-06 03:55:36

我能够使用 LINQ 获得结果:

from g in Genres
from t in g.Titles
where g.Name == "Horror"
select t

这样我就不需要使用 Expand。我还可以使用以下 URL: http:// /odata.netflix.com/Catalog/Genres('Horror')/Titles() 获得相同的结果。此帖子< Chris Woodruff 的 /a> 帮助我理解了这个问题。

I was able to get my results using the LINQ:

from g in Genres
from t in g.Titles
where g.Name == "Horror"
select t

This way I don't need to use Expand. I can also use the URL: http://odata.netflix.com/Catalog/Genres('Horror')/Titles() to get the same results. This post by Chris Woodruff helped me understand the issue.

心病无药医 2024-09-06 03:55:36

如果您收到 DataServiceQueryException 以及以下消息:请求版本“1.0”对于响应而言太低。支持的最低版本是“2.0”

您需要将 .Net 版本升级到 .Net Framework 4 并下载 LINQPad for .NET Framework 4.0

If you are receiving an DataServiceQueryException along with the message: Request version '1.0' is too low for the response. The lowest supported version is '2.0'.

You need to upgrade your version of .Net to .Net Framework 4 and download LINQPad for .NET Framework 4.0

倚栏听风 2024-09-06 03:55:36

凯尔,
这将为您提供按流派列出的所有电影的列表。

(from g in Genres.Expand("Titles")
where g.Name == "Horror"
select g).Dump();

这将在 LinqPad 中创建以下 URL

/Catalog/Genres('Horror')?$expand=Titles

有趣的是,我需要使用 .Expand 语法来获取它。
当我使用浏览器浏览 netflix odata feed 并想要相同的数据时,我可以通过以下 URL 获取它: http://netflix.cloudapp.net/Catalog/Genres('Horror')/Titles

一定有一种方法可以在不 .Expand 的情况下获得它

Kyle,
This will get you a listing of all movies by Genre

(from g in Genres.Expand("Titles")
where g.Name == "Horror"
select g).Dump();

This creates the following URL in LinqPad

/Catalog/Genres('Horror')?$expand=Titles

Its interesting that I needed to use the .Expand syntax to get it.
When I browse to the netflix odata feed with my browser and want the same data I can get it with the following URL: http://netflix.cloudapp.net/Catalog/Genres('Horror')/Titles

There must be a way to get at it without .Expand

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