How to perform an ODATA expand in LinqPad

六月ゝ 毕业季﹏ 提交于 2019-12-04 23:17:19

问题


I'm using LINQPad to connect to the ODATA services on a local CRM organization and I don't know how to perform "joins" or to traverse relationships using LINQPad.

Here is my URL

OrganizationData.svc/New_locationSet?$select=new_state_new_location/new_Region$expand=new_state_new_location

which works just fine in the browser. Here is what I'm doing in LINQPad:

from l in new_locationSet
from s in l.new_state_new_location
select s.new_Region

but I'm getting an error:

An expression of type 'LINQPad.User.New_state' is not allowed in a subsequent from clause in a query expression with source type 'System.Data.Services.Client.DataServiceQuery<LINQPad.User.New_location>'.  Type inference failed in the call to 'SelectMany'.

Any ideas? I've found the LINQPad OData documentation extremely lacking...


回答1:


You just need to project out what you want to expand, e.g.:

from p in Products
select new {p.Name, CategoryName = p.Category.Name}

or

Products.Select(p => new { p.Name, CategoryName = p.Category.Name})

will yield

http://services.odata.org/(S(readwrite))/OData/OData.svc/Products()?$expand=Category&$select=Name,Category/Name

in LinqPad's Request Log tab.



来源:https://stackoverflow.com/questions/11251763/how-to-perform-an-odata-expand-in-linqpad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!