加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net – 使用OData $select来从相关对象中挑选字段

发布时间:2020-12-16 06:39:16 所属栏目:asp.Net 来源:网络整理
导读:我正在使用带有OData V4的WebAPI 2.2. 我可以使用$filter = RelatedObj / PropertyName eq’Some Value’来根据相关的对象属性值过滤实体列表. 但是,当我尝试使用与$select相同的语法时: $select=Id,Name,RelatedObj/PropertyName 结果例外: "message": "T
我正在使用带有OData V4的WebAPI 2.2.

我可以使用$filter = RelatedObj / PropertyName eq’Some Value’来根据相关的对象属性值过滤实体列表.

但是,当我尝试使用与$select相同的语法时:

$select=Id,Name,RelatedObj/PropertyName

结果例外:

"message": "The query specified in the URI is not valid. Found a path with multiple navigation properties or a bad complex property path in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.","innererror": {
"message": "Found a path with multiple navigation properties or a bad complex property path in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.","type": "Microsoft.OData.Core.ODataException",

这可以解决吗?

解决方法

您可以使用$expand和嵌套$select查询选项来完成

$select=Id,Name&$expand=RelatedObj($select=PropertyName)

见ODATA documentation

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读