I am having challenges with odata query to get derived type:
{{Url}}/odata/resource?$expand=derivedType
See this link which gives options like ~/People/OfTy
The information in that blog post is out of date. The official OData specifications are available at http://www.odata.org/documentation/.
In OData v4, you can filter by derived type by appending the fully-qualified name of the derived type to the resource URI path. For example, GET http://host/Employees/MyService.Manager
would retrieve the subset of Employees who are also Managers (assuming Manager is derived from Employee type). The prefix MyService
in the last path segment is the OData namespace in which the Manager
type is defined.
You can also filter by derived type when expanding a navigation property by appending the fully-qualified name of the derived type to the name of the property in an $expand
clause. For example, GET http://host/Companies('Acme')?$expand=Employees/MyService.Manager
would retrieve the Company named Acme with all Managers expanded inline.
This is an exerpt from OData 4.0 convention docs:
Any resource path or path expression identifying a collection of entities or complex type instances can be appended with a path segment containing the qualified name of a type derived from the declared type of the collection. The result will be restricted to instances of the derived type and may be empty. Any resource path or path expression identifying a single entity or complex type instance can be appended with a path segment containing the qualified name of a type derived from the declared type of the identified resource. If used in a resource path and the identified resource is not an instance of the derived type, the request will result in a 404 Not Found response. If used in a path expression that is part of a Boolean expression, the type cast will evaluate to null. Example 30: entity set restricted to VipCustomer instances
http://host/service/Customers/Model.VipCustomer
Example 31: entity restricted to a VipCustomer instance, resulting in 404 Not Found if the customer with key 1 is not a VipCustomerhttp://host/service/Customers/Model.VipCustomer(1) http://host/service/Customers(1)/Model.VipCustomer
Example 32: cast the complex property Address to its derived type DetailedAddress, then get a property of the derived typehttp://host/service/Customers(1)/Address/Model.DetailedAddress/Location
Example 33: filter expression with type cast; will evaluate to null for all non-VipCustomer instances and thus return only instances of VipCustomerhttp://host/service/Customers?$filter=Model.VipCustomer/PercentageOfVipPromotionProductsOrdered gt 80
Example 34: expand the single related Customer only if it is an instance of Model.VipCustomer. For to-many relationships only Model.VipCustomer instances would be inlined,http://host/service/Orders?$expand=Customer/Model.VipCustomer