2017-12-13 5 views
0

Ich versuche, diese Abfrage zu beantragen:OData: Reisen Abfrage Fehler Casting komplexe Typen

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

Also, ich versuche alle AirportLocation von People('russellwhyte') zu bekommen. Allerdings erhalte ich diese Fehlermeldung:

"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": {... 
} 

Dies ist das Location komplexer Typ verwandte Schema:

<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> 

So Location komplexer Typ ist der Basistyp von AirportLocation und EventLocation.

irgendwelche Ideen?

Antwort

0

Vielleicht Der Reisedienst hatte keine solche Funktionalität implementiert. Es wird jedoch in OData unterstützt.

Grundsätzlich sollten Sie im Conventions-Routing die entsprechenden Methoden im Controller hinzufügen. Wenn Sie die Folge Vererbung Zum Beispiel haben:

Address 
CnAddress : Address 
UsAddress : Address 

Entitätstyp Customer hat Eigenschaft Locations mit Typ namens IList<Address>

sollten Sie Methode GetLocationsOfCnAddress oder GetLocationsOfUsAddress im CustomersController : ODataController

mit dem Namen
+0

Können Sie mir bieten jede Was hilft Dokumentation, warum sollte ich eine "GetLocationsOfCnAddress" und eine "GetLocationsOfUsAddress" haben? Auf der anderen Seite, wissen Sie, dass ein Service diese Funktionalität wirklich unterstützt? – Jordi

+0

Sie finden einige Dokumente zum Convention Routing: http://odata.github.io/WebApi/#03-02-built-in-routing-conventions. Aber es erwähnt nicht die Eigentumsform. Vielleicht können Sie auf die Codes verweisen: https://github.com/OData/WebApi/blob/master/src/System.Web.OData/OData/Routing/Conventions/PropertyRoutingConvention.cs#L65-L67 –