OData:Trips查询错误转换复杂类型

时间:2017-12-13 12:12:17

标签: odata

我试图请求此查询:

http://services.odata.org/V4/TripPinService/People('russellwhyte')/AddressInfo/Microsoft.OData.SampleService.Models.TripPin.AirportLocation

所以,我试图从AirportLocation获取所有People('russellwhyte')。但是,我收到此错误消息:

"error": {
    "code": "InternalServerError",
    "message": "Type cast segment 'Microsoft.OData.SampleService.Models.TripPin.AirportLocation' after a collection which is not of entity type is not allowed.",
    "innererror": {...
}

这是与Location复杂类型相关的架构:

<ComplexType Name="Location" OpenType="true">
    <Property Name="Address" Type="Edm.String" Nullable="false" />
    <Property Name="City" Type="Microsoft.OData.SampleService.Models.TripPin.City" Nullable="false" />
</ComplexType>
<ComplexType Name="EventLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
    <Property Name="BuildingInfo" Type="Edm.String" />
</ComplexType>
<ComplexType Name="AirportLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
     <Property Name="Loc" Type="Edm.GeographyPoint" Nullable="false" SRID="4326" />
</ComplexType>

因此,Location复杂类型是AirportLocationEventLocation的基本类型。

任何想法?

1 个答案:

答案 0 :(得分:0)

也许旅行服务没有实现这样的功能。但是,它确实支持OData。

基本上,在常规路由中,您应该在控制器中添加相应的方法。例如,如果您具有以下继承:

Address
CnAddress : Address
UsAddress : Address

实体类型Customer具有名为Locations的属性,其类型为IList<Address>

您应该在GetLocationsOfCnAddress

中使用名为GetLocationsOfUsAddressCustomersController : ODataController的方法