如何通过 Netflix OData API 正确使用匿名类型

发布于 2024-10-09 05:22:52 字数 287 浏览 0 评论 0原文

我正在尝试在 LINQPad 中使用下面的查询。它不起作用。我收到这个异常:

NotSupportedException:不支持使用表达式 t.BoxArt.SmallUrl 构造或初始化类型 <>f__AnonymousType0`1[System.String] 的实例。

from t in Titles where t.Id == "ApUFq" select new { t.BoxArt.SmallUrl }

I am trying to use the query below in LINQPad. It isnt working. I am getting this exception:

NotSupportedException: Constructing or initializing instances of the type <>f__AnonymousType0`1[System.String] with the expression t.BoxArt.SmallUrl is not supported.

from t in Titles where t.Id == "ApUFq" select new { t.BoxArt.SmallUrl }

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

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

发布评论

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

评论(2

救赎№ 2024-10-16 05:22:52

我不熟悉 Netflix OData API,但您的问题似乎是 LINQ 的常见障碍。

试试这个:

from t in Titles
where t.Id == "ApUFq"
select new t.BoxArt.SmallUrl;

或者:

from t in Titles.Where(t0 => t0.Id == "ApUFq").ToArray()
select new { t.BoxArt.SmallUrl };

一个或两个应该适合你。

I'm not familiar with the Netflix OData API, but your issue appears to be a common stumbling block with LINQ.

Try this instead:

from t in Titles
where t.Id == "ApUFq"
select new t.BoxArt.SmallUrl;

Or alternatively:

from t in Titles.Where(t0 => t0.Id == "ApUFq").ToArray()
select new { t.BoxArt.SmallUrl };

One or both should work for you.

抹茶夏天i‖ 2024-10-16 05:22:52

WCF 数据服务客户端 linq 处理器仅支持具有成员绑定分配的投影。这意味着当您投影出一个字段时,您需要将其分配给投影类型中的另一个字段。

NotSupportedException:不支持使用表达式 t.BoxArt.SmallUrl 构造或初始化类型 <>f__AnonymousType0`1[System.String] 的实例。

来自标题中的 t
其中 t.Id == "ApUFq"
选择新的{smallUrl = t.BoxArt.SmallUrl}

The WCF Data Services client linq processor only supports projections which have member bind assignments. Which means that when you project out a field, you need to assign it to another field in the projected type.

NotSupportedException: Constructing or initializing instances of the type <>f__AnonymousType0`1[System.String] with the expression t.BoxArt.SmallUrl is not supported.

from t in Titles
where t.Id == "ApUFq"
select new { smallUrl = t.BoxArt.SmallUrl }

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