简体   繁体   English

odata如何知道ID是哪个属性?

[英]How does odata know which property is the ID?

In the following example russelwhyte is the id, but how does the provider know to map it to the UserName property? 在下面的示例中,russelwhyte是id,但是提供程序如何知道将其映射到UserName属性?

    URL: http://services.odata.org/V4/TripPinServiceRW/People?$format=application/json;odata.metadata=full
Response:
{
    @odata.context: "http://services.odata.org/V4/(S(ck3fzk3dze0kmzjcruxiz31i))/TripPinServiceRW/$metadata#People",
    @odata.nextLink: "http://services.odata.org/V4/TripPinServiceRW/People?%24format=application%2fjson%3bodata.
    metadata%3dfull&%24skiptoken=8",
    value:
    [
        {
            @odata.type: "#Microsoft.OData.SampleService.Models.TripPin.Person",
            @odata.id: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')",
            @odata.etag: "W/"08D17DBDFB9CCAAC"",
            @odata.editLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')",
            UserName: "russellwhyte",
            FirstName: "Russell",
            LastName: "Whyte",
            ...
            Friends@odata.associationLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')/Friends/$ref",
            Friends@odata.navigationLink: "http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')/Friends",
            ...
        },
        ...
    ]
}

通过重写基类EntitySetController GetEntityByKey

Query the metadata document, you can get the model schema for the service, and in which you can find which properties are the keys/IDs. 查询元数据文档,可以获得服务的模型架构,并在其中可以找到哪些属性是键/ ID。

For example: 例如:

GET: http://services.odata.org/V4/(S(ksn5grnrgbebt44osly5z2vr))/TripPinServiceRW/ $metadata GET: http : //services.odata.org/V4/( S(ksn5grnrgbebt44osly5z2vr))/ TripPinServiceRW/ $ metadata

<EntityType Name="Person" OpenType="true">
  <Key>
    <PropertyRef Name="UserName"/>
  </Key>
  <Property Name="UserName" Type="Edm.String" Nullable="false">
    <Annotation Term="Org.OData.Core.V1.Permissions">
      <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
    </Annotation>
  </Property>
  <Property Name="FirstName" Type="Edm.String" Nullable="false"/>
  <Property Name="LastName" Type="Edm.String" Nullable="false"/>
  <Property Name="Emails" Type="Collection(Edm.String)"/>
  <Property Name="AddressInfo" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Location)"/>
  <Property Name="Gender" Type="Microsoft.OData.SampleService.Models.TripPin.PersonGender"/>
  <Property Name="Concurrency" Type="Edm.Int64" Nullable="false">
    <Annotation Term="Org.OData.Core.V1.Computed" Bool="true"/>
  </Property>
  <NavigationProperty Name="Friends" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)"/>
  <NavigationProperty Name="Trips" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" ContainsTarget="true"/>
  <NavigationProperty Name="Photo" Type="Microsoft.OData.SampleService.Models.TripPin.Photo"/>
</EntityType>

暂无
暂无

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

相关问题 Angular如何知道要调用哪个Spring Boot REST API? - How does Angular know which Spring Boot REST API to invoke? 在摘要身份验证中,服务器如何知道它在之前的调用中向哪个客户端发送了哪个随机数? - In digest authentication, How does the server know which nonce it had sent in earlier call to which client? Angularjs $ resource,我如何知道将哪个obj传递给它? 网址未收到:id - Angularjs $resource, how do I know which obj is being passed to it? URL not receiving :id 消费者会知道 RESTful URL 是基于 OData 还是简单的 RESTful api url? 有关系吗? - Would a consumer know if the RESTful URL is OData based or the simple RESTful api url? Does it matter? 如何通过odata URI中的mongodb对象ID获取数据? - How to get data by mongodb object id in odata URI? 如何在属性不存在的情况下过滤OData集合? - How to filter OData collection where attribute does not exist? 页面大小在嵌套 OData 查询中如何工作? - How does the page size work in nested OData query? 如何编写OData调用以获取具有等于空数组的特定属性的所有实体 - How to write an OData call to get all entities with a specific property equal to an empty array OData违反了关注点吗? - Does OData violate separation of concern? 如何实现显示ASP.NET Web API OData服务可用的所有方法的页面? - How to implement a page which displays all methods available with an ASP.NET Web API OData Service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM