Search code examples
restodata

Cross-Service references in OData


I would like to implement an OData v4 service in which Entity Sets are grouped into namespaces. As OData URI's are composed of serviceEndpoint/entitySetName, and entitySetName cannot contain slashes, I would like to implement each namespace is represented as a separate service, ie:

https://www.mycompany.com/namespace1/entitySetA
https://www.mycompany.com/namespace2/entitySetB

Where namespace1 and namespace2 are represented as separate OData services. This all works fine, until I need to add a NavigationProperty from entitySetA to entitySetB. Is it possible for entities from one service to refer to those of another for navigation properties? Are there any examples I could see of how this is implemented at the service level?

Thanks!


Solution

  • In short, no, it is not possible in OData v4 to have Entities that refer to Entites from other services.

    To achieve the namespacing my application required, I created dummy singleton entities to represent those namespace. For the example above, my service would expose no Entity Sets, but two singletons, named namespace1 (with Navigation Property entitySetA), and namespace2 (with Navigation Property entitySetB). It abuses the Entity Data Model a bit, but the user experience is quite good, both when consuming via direct HTTP calls, and by client.