[英]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.