oData $expand on Derived Types

后端 未结 2 1977
囚心锁ツ
囚心锁ツ 2021-01-07 07:00

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

2条回答
  •  暖寄归人
    2021-01-07 07:28

    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 VipCustomer

    http://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 type

    http://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 VipCustomer

    http://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

提交回复
热议问题