Search code examples
c#.netasp.net-web-apiodata

Entities inheritance in OData


I have a PoC service similar odata.org's demo service
So in thier demo they have a Person base type and Customer and Employee derived types.

I want to query for all (or filtered) the instances of the derived type Employee.
Since the spec says "An entity can be a member of at most one entity set at any given point in time. Entity sets provide entry points into the data model."
The entry point for Employees is through the Persons EntitySet, so far so good.
But I'm just can't find a way to filter by the @odata.type.

I've tried many queries like:

/[email protected] eq ODataDemo.Employee
/Persons?$filter=odata.type eq ODataDemo.Employee
/Persons?$filter=type eq ODataDemo.Employee
...
(The root is: http://services.odata.org/V4/OData/(S(eq1ncar1ktn55khwjrukic3c))/OData.svc/Persons )

But nothing returned 200 OK status code.


Solution

  • Try as following Uri:

    http://services.odata.org/V4/OData/(S(eq1ncar1ktn55khwjrukic3c))/OData.svc/Persons/ODataDemo.Employee
    

    The related spec: Addressing Derived Types