简体   繁体   English

NET Webapi Odata Client中的http:// localhost / Odata / User(1)/ Contacts等效项

[英]Equivalent of http://localhost/Odata/User(1)/Contacts in .NET webapi Odata Client

I am working on an WebApi based OData service with navigated properties. 我正在使用具有导航属性的基于WebApi的OData服务。 I can get results using filter and contacts however what i am interested is in whether is there a way of expressing in .net which would resolve in Contacts query to the server. 我可以使用过滤器和联系人来获取结果,但是我感兴趣的是是否有一种在.net中表示的方式,该方式可以在对服务器的联系人查询中解决。 The goal is to achieve the result by using the proxy classes generated on client side. 目的是通过使用客户端生成的代理类来获得结果。

http://mydevserver/Odata/User(1)/Contacts

Trying This 试试这个

Dim query = From c In cont.User.Expand("Contacts") Where c.Id = userId
Results In 结果是

 http://localhost/Odata/User(1)?$expand=Contacts http:// localhost / Odata / User(1)?$ expand =联系人 

Gives me This I have tried using LINQ and inline query but i cannot produce exact same query. 给我我尝试使用LINQ和内联查询,但是我无法产生完全相同的查询。 If i run that same in fiddler. 如果我在提琴手中也一样。 I can see the results of the related contacts for the user. 我可以为用户查看相关联系人的结果。 May be i am missing something. 可能是我缺少了一些东西。 Can please somebody point me in right direction. 可以请有人指出我正确的方向。 Thanks 谢谢

Suppose you are using OData Client, You can try following codes. 假设您正在使用OData Client,则可以尝试以下代码。

    Dim queryUser = (From p In cont.UserWhere c.Id = userId).First()
    Dim contact As QueryOperationResponse(Of Contact) = cont.LoadProperty(queryUser, "Contacts")

This code will send two request: 此代码将发送两个请求:

~/Odata/User(1) 〜/ Odata /用户(1)

~/Odata/User(1)/Contacts 〜/ Odata /用户(1)/联系人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM