【问题标题】:How can I order objects according to some attribute of the child in OData?如何根据 OData 中子项的某些属性对对象进行排序?
【发布时间】:2012-09-24 19:32:16
【问题描述】:

我正在尝试使用此 URL 在 OData 中进行一些自定义排序

localhost:82/odata.svc/ComponentPresentations?$filter=TemplateId eq 2894 and publicationId eq 10&$expand=Component/Keywords?$orderby=Title desc

其中ComponentComponentPresentation的属性,KeywordsComponent的属性,我想根据关键字的Title属性对ComponentPresentation进行排序。但是关键字和标题是组件表示的属性

有没有办法根据 Keword 的 title 属性对结果进行排序?哪个是Component的子代,哪个是ComponentPresentation的子代?

【问题讨论】:

  • @VladL 以上...(对不起,我没有代表点评论),我认为这也行不通。我刚刚尝试了一下,并将 Quantity 添加到 Order_Details 的 select 语句中:services.odata.org/V4/Northwind/Northwind.svc/… 看来 Order_Details 没有按 Quantity 排序。

标签: odata


【解决方案1】:

只想提一下,从 OData V4 开始就有可能。您可以根据需要嵌套任意数量的扩展/选择/排序/过滤器。现在就这么简单

http://services.odata.org/V4/Northwind/Northwind.svc/Orders?$select=OrderID&$expand=Order_Details($select=UnitPrice;$orderby=Quantity)

【讨论】:

  • 语法是正确的,但是嵌套的 orderby 似乎并没有改变结果中的任何内容。
  • @sroll 我花了很多时间使用 odata.org 的示例 OData 服务,并注意到如果服务根本没有关闭,您会在不同的时间得到不同的结果;) 试试看TripPin odata.org/odata-services
  • 如果语法正确,那就奇怪了,那就不行了:s
  • @inane v1、v2 和 v3 - 不可能
  • 这个语法是正确的,但问题是它不对订单进行排序,它只对每个订单中的 order_details 进行排序。
【解决方案2】:

可以通过嵌套的单基数属性对结果进行排序,例如:http://services.odata.org/V3/Northwind/Northwind.svc/Orders?$top=50&$expand=Customer&$orderby=Customer/City

AFAIK,不可能使用具有许多基数的导航属性来执行此操作(尽管在扩展场景中对扩展提要中返回的内容进行排序很有用)。

【讨论】:

    【解决方案3】:

    在查询结束时使用扩展对象/字段附加顺序

    localhost:82/odata.svc/ComponentPresentations?$filter=TemplateId eq 2894 和 publicationId eq 10&$expand=Component/Keywords?$orderby=Component/Title desc

    【讨论】:

      猜你喜欢
      • 2010-10-04
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 2015-11-16
      • 2011-08-13
      • 1970-01-01
      • 2022-08-22
      • 2020-12-05
      相关资源
      最近更新 更多