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

标签 .net asp.net-web-api odata asp.net-web-api-odata

我正在将 WebAPI 2.2 与 OData V4 结合使用。

我可以使用 $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

关于.net - 使用 OData $select 从相关对象中挑选字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30868614/

相关文章:

c# - 无法访问 asp :TextBox tag from the C# file : the name 'txtUsername' does not exist in the current context

c# - Db 行更改的审计历史记录

asp.net-mvc - 执行 PostAsync 时为什么等待不起作用?

odata - 如何为 SAPUI5 TreeTable 创建 OData 服务?

asp.net-web-api - 如何返回与在 OData 中运行查询的对象不同的对象?

.net - 如何为文件系统实现 OData 服务

c# - 无法添加到 IPgedList 对象或将 List<T> 传输到 IPgedList<T>

.net - WCF - 自定义客户端请求/响应 XML

angularjs - $http : how to get filename of headers from WebApi with CORS

c# - 名为 'MS_attributerouteWebApi' 的路由已经在路由集合中