In the following inheritance hierarchy, I have an action called 'SetWheelCount' defined for the Motorcyle entity type.
Vehicle -> Motorcycle -> SportBike
In my controller i am returning an instance of Motorcycle for which i expected to see an action advertisement, but there is no advertisement.
Model:
------
static IEdmModel GetImplicit_InheritanceModel()
{
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
var vehicles = modelBuilder.EntitySet<Vehicle>("Vehicles");
var config = modelBuilder.Entity<Motorcycle>().Action("SetWheelCount");
config.Parameter<int>("newCount");
config.ReturnsFromEntitySet<Vehicle>("Vehicles");
return modelBuilder.GetEdmModel();
}
Metadata
--------
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="ODataService" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="Vehicle">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="Model" Type="Edm.String" />
<Property Name="Name" Type="Edm.String" />
<Property Name="WheelCount" Type="Edm.Int32" Nullable="false" />
</EntityType>
<EntityType Name="Motorcycle" BaseType="ODataService.Vehicle">
<Property Name="CanDoAWheelie" Type="Edm.Boolean" Nullable="false" />
</EntityType>
<EntityType Name="Car" BaseType="ODataService.Vehicle">
<Property Name="SeatingCapacity" Type="Edm.Int32" Nullable="false" />
</EntityType>
<EntityType Name="SportBike" BaseType="ODataService.Motorcycle">
<Property Name="TopSpeed" Type="Edm.Int64" Nullable="false" />
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="Container">
<EntitySet Name="Vehicles" EntityType="ODataService.Vehicle" />
<FunctionImport Name="SetWheelCount" ReturnType="ODataService.Vehicle" IsBindable="true" EntitySet="Vehicles" m:IsAlwaysBindable="true">
<Parameter Name="bindingParameter" Type="ODataService.Motorcycle" />
<Parameter Name="newCount" Type="Edm.Int32" />
</FunctionImport>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Controller:
---------
public class VehiclesController : ApiController
{
public IEnumerable<Vehicle> Get()
{
List<Vehicle> vehicles = new List<Vehicle>();
vehicles.Add(new Motorcycle()
{
Id = 1,
Model = "Ducati",
Name = "Z50",
CanDoAWheelie = true,
});
return vehicles;
}
}
Response:
----------
HTTP/1.1 200 OK
Content-Length: 303
Content-Type: application/json; odata=verbose; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
DataServiceVersion: 3.0;
Date: Mon, 08 Oct 2012 21:56:21 GMT
{
"d":{
"results":[
{
"__metadata":{
"id":"http://kirandesktop:50231/Vehicles(1)","uri":"http://kirandesktop:50231/Vehicles(1)","type":"ODataService.Motorcycle"
},"Id":1,"Model":"Ducati","Name":"Z50","WheelCount":2,"CanDoAWheelie":true
}
]
}
}
Comments: As discuss there was no repro.
Vehicle -> Motorcycle -> SportBike
In my controller i am returning an instance of Motorcycle for which i expected to see an action advertisement, but there is no advertisement.
Model:
------
static IEdmModel GetImplicit_InheritanceModel()
{
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
var vehicles = modelBuilder.EntitySet<Vehicle>("Vehicles");
var config = modelBuilder.Entity<Motorcycle>().Action("SetWheelCount");
config.Parameter<int>("newCount");
config.ReturnsFromEntitySet<Vehicle>("Vehicles");
return modelBuilder.GetEdmModel();
}
Metadata
--------
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="ODataService" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="Vehicle">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="Model" Type="Edm.String" />
<Property Name="Name" Type="Edm.String" />
<Property Name="WheelCount" Type="Edm.Int32" Nullable="false" />
</EntityType>
<EntityType Name="Motorcycle" BaseType="ODataService.Vehicle">
<Property Name="CanDoAWheelie" Type="Edm.Boolean" Nullable="false" />
</EntityType>
<EntityType Name="Car" BaseType="ODataService.Vehicle">
<Property Name="SeatingCapacity" Type="Edm.Int32" Nullable="false" />
</EntityType>
<EntityType Name="SportBike" BaseType="ODataService.Motorcycle">
<Property Name="TopSpeed" Type="Edm.Int64" Nullable="false" />
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="Container">
<EntitySet Name="Vehicles" EntityType="ODataService.Vehicle" />
<FunctionImport Name="SetWheelCount" ReturnType="ODataService.Vehicle" IsBindable="true" EntitySet="Vehicles" m:IsAlwaysBindable="true">
<Parameter Name="bindingParameter" Type="ODataService.Motorcycle" />
<Parameter Name="newCount" Type="Edm.Int32" />
</FunctionImport>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Controller:
---------
public class VehiclesController : ApiController
{
public IEnumerable<Vehicle> Get()
{
List<Vehicle> vehicles = new List<Vehicle>();
vehicles.Add(new Motorcycle()
{
Id = 1,
Model = "Ducati",
Name = "Z50",
CanDoAWheelie = true,
});
return vehicles;
}
}
Response:
----------
HTTP/1.1 200 OK
Content-Length: 303
Content-Type: application/json; odata=verbose; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
DataServiceVersion: 3.0;
Date: Mon, 08 Oct 2012 21:56:21 GMT
{
"d":{
"results":[
{
"__metadata":{
"id":"http://kirandesktop:50231/Vehicles(1)","uri":"http://kirandesktop:50231/Vehicles(1)","type":"ODataService.Motorcycle"
},"Id":1,"Model":"Ducati","Name":"Z50","WheelCount":2,"CanDoAWheelie":true
}
]
}
}
Comments: As discuss there was no repro.