oData $ expand派生类型 [英] oData $expand on Derived Types

查看:222
本文介绍了oData $ expand派生类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用odata查询获取派生类型方面遇到了挑战:

I am having challenges with odata query to get derived type:

{{Url}}/odata/resource?$ expand = derivedType

{{Url}}/odata/resource?$expand=derivedType

请参见此链接,该链接像这样的选项 〜/People/OfType('Employee')(41)/Manager或〜/People!Employee不起作用.

See this link which gives options like ~/People/OfType('Employee')(41)/Manager or ~/People!Employee which didn't work.

带有EF6的Asp.Net Web Api 2支持吗?什么是查询?

Is this supported with Asp.Net Web Api 2 with EF6? What would be the query?

推荐答案

这是OData 4.0约定文档的摘录:

This is an exerpt from OData 4.0 convention docs:

任何资源路径或路径表达式,用于标识以下内容的集合 实体或复杂类型实例可以附加路径段 包含从声明的类型派生的类型的限定名称 的集合.结果将仅限于 派生类型,可以为空.任何资源路径或路径表达式 可以附加单个实体或复杂类型实例的标识 包含包含派生类型的限定名称的路径段 从所标识资源的声明类型中获取.如果用于 资源路径,并且标识的资源不是该资源的实例 派生类型,该请求将导致404 Not Found响应.如果 在布尔表达式的一部分路径表达式中使用时, 类型强制转换将计算为null.示例30:实体集仅限于 VipCustomer实例

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
示例31:实体 限制为VipCustomer实例,如果出现404,则找不到 密钥为1的客户不是VipCustomer

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
示例32:演员表 将复杂的属性Address转换为其派生类型的DetailedAddress,然后 获取派生类型的属性

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://主机/服务/客户(1) /Address/Model.DetailedAddress/Location
示例33:类型转换为filter的表达式;将评估为null 对于所有非VipCustomer实例,因此仅返回的实例 VipCustomer

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
示例34:仅当单个相关客户是 Model.VipCustomer的实例.仅适用于多对多关系 Model.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

http://host/service/Orders?$expand=Customer/Model.VipCustomer

这篇关于oData $ expand派生类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆