I'm using breezejs with WebApi OData according to this sample. As stated in this article I cannot use ODataConventionModelBuilder because of the missing foreign key information. Suppose I have an entity named 'Car' which is derived from an entity named 'Vehicle'. With ODataConventionModelBuilder I can define a model such as this:
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Vehicle>("Vehicles");
builder.EntitySet<Car>("Cars");
I can do the query like :
- /odata/Vehicles --> returns all the vehicles.
- /odata/Cars --> returns just the cars.
But with Breeze EdmBuilder class I can only use the '/odata/Vehicles' query. The '/odata/Cars' would result in a '404 not found' error.
It seems that when using 'ODataConventionModelBuilder', the 'Cars' entity set is defined in the metadata but when using the breeze EdmBuilder, it is not. I can confirm this behavior when sending request to the metadata end point('odata/$metadata'). This happens for both code first and model first approaches stated in this question.
In short, how do I use inheritance when using EdmBuilder class in breeze and Web Api OData.
UPDATED
here is the metadata when using 'ODataConventionModelBuilder':
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="EFTest.Models">
<EntityType Name="Vehicle">
<Key>
<PropertyRef Name="VehicleId"/>
</Key>
<Property Name="VehicleId" Type="Edm.Int32" Nullable="false"/>
<Property Name="Name" Type="Edm.String"/>
</EntityType>
<EntityType Name="Car" BaseType="EFTest.Models.Vehicle">
<Property Name="Capacity" Type="Edm.Int32" Nullable="false"/>
</EntityType>
</Schema>
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="Default">
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Vehicles" EntityType="EFTest.Models.Vehicle"/>
<EntitySet Name="Cars" EntityType="EFTest.Models.Car"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
here is metadata when using breeze EdmBuilder class:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="TestDBModel">
<EntityType Name="Car" BaseType="TestDBModel.Vehicle">
<Property Name="Capacity" Type="Edm.Int32" Nullable="false"/>
</EntityType>
<EntityType Name="Vehicle">
<Key>
<PropertyRef Name="VehicleId"/>
</Key>
<Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="VehicleId" Type="Edm.Int32" Nullable="false" p6:StoreGeneratedPattern="Identity"/>
<Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true"/>
</EntityType>
<EntityContainer xmlns:p5="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="TestDBEntities" p5:LazyLoadingEnabled="true">
<EntitySet Name="Vehicles" EntityType="TestDBModel.Vehicle"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
here is the conceptual model section in the edmx file:
<edmx:ConceptualModels>
<Schema Namespace="TestDBModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="Car" BaseType="TestDBModel.Vehicle">
<Property Name="Capacity" Type="Int32" Nullable="false" />
</EntityType>
<EntityType Name="Vehicle">
<Key>
<PropertyRef Name="VehicleId" />
</Key>
<Property Name="VehicleId" Nullable="false" annotation:StoreGeneratedPattern="Identity" Type="Int32" />
<Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
</EntityType>
<EntityContainer Name="TestDBEntities" annotation:LazyLoadingEnabled="true">
<EntitySet Name="Vehicles" EntityType="Self.Vehicle" />
</EntityContainer>
</Schema>
</edmx:ConceptualModels>