0

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>
Community
  • 1
  • 1
Arash
  • 1
  • 1
  • 1
  • How is `Car` defined in the metadata? Would you please update your question with short snippets of the metadata for both the `Car` and `Vehicle` classes? Ultimately, if necessary, you can repair the damage with client-side coded metadata. But it would be nice to generate the right metadata on the server if we can. – Ward Apr 05 '14 at 16:19
  • @Ward: updated to include metadata for a sample model. – Arash Apr 05 '14 at 18:53

1 Answers1

0

What stands out for me is that the Cars "EntitySet" is missing from the EDMX conceptual model and, consequently, from the metadata generated by EdmBuilder. OTOH, you included Cars when you called ODataConventionModelBuilder.

You aren't really talking about the same "model".

I think (hope) you will get the desired outcome if you add the Cars "EntitySet" to the DbContext.

Ward
  • 17,793
  • 4
  • 37
  • 53
  • This sample is a model first EF context, so I guess this is by design. Because the derived type (Car) is shown on the edmx designer but it is not included as an EntitySet. I also checked it with a code first dbcontext. Including the 'Cars' as an EntitySet has no effect. – Arash Apr 06 '14 at 09:46
  • That just doesn't make sense. I take it that this is a tiny sample that we could easily load and understand. If so, would you put it somewhere that we can download and try? We need real code. Thanks. – Ward May 02 '14 at 20:50