在以下示例中,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",
...
},
...
]
}
答案 0 :(得分:0)
覆盖基类GetEntityByKey
EntitySetController
答案 1 :(得分:0)
查询元数据文档,您可以获取服务的模型架构,并且您可以在其中找到哪些属性是键/ ID。
例如:
获取:http://services.odata.org/V4/(S(ksn5grnrgbebt44osly5z2vr))/TripPinServiceRW/ $元数据
<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>