开发者

How to properly use anonymous type with Netflix OData API

开发者 https://www.devze.com 2023-02-01 07:17 出处:网络
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.S

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 supp开发者_开发技巧orted.

from t in Titles where t.Id == "ApUFq" 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.



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 }

0

精彩评论

暂无评论...
验证码 换一张
取 消