locked
Metadata and contained entities RRS feed

  • Question

  • User1109032827 posted

    I'm hoping someone here can help settle a matter. I've been searching for a definitive answer for a while and have come up empty.

    We're building an OData Web API and a question has come up around the metadata. We have a couple of cases where we use contained entities. That is, entity B is only accessible through entity A. So a request to get entity type B with the ID 2 might look like this: http://www.myapi.com/v1.0/A(1)/B(2).  It is not possible to request http://www.myapi.com/v1.0/B(2) directly.

    Functionally this all works fine. We just had to specify the navigation targets during startup. The issue, if there is one, is in how the metadata for our endpoint is generated. Entity types A and B are both listed at the same level of the metadata. E.g.:

    <EntityType Name="A">
      <Key>
        <PropertyRef Name="AId" />
      </Key>
      ...properties...
      <NavigationProperty Name="B" Type="Collection(Myapi.Graph.Models.B)" />
    </EntityType>
    <EntityType Name="B">
      <Key>
        <PropertyRef Name="BId" />
      </Key>
    ...properties... </EntityType>

    There is a disagreement over whether or not this is syntactically correct. Some feel that because entity type B is not available at the top level of the API it should not be at the same level of the metadata as entity type A. Others feel that entity type A correctly specifies a navigation property for entity type B, and because B is, in fact, an entity, that this is all as it should be.

    I've been unable to find documentation of any other way for the metadata to be structured in this situation, which leads me to suspect that the above is correct and valid, but I'd like to find something definitive one way or the other. If anyone can point me towards something like that I would be most grateful.

    Tuesday, December 20, 2016 4:37 PM

All replies