微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在使用带有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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐