简体   繁体   English

数组属性上的 OData 过滤器以返回空数组或数组

[英]OData filter on array property to return empty array or array

I have a JSON object similar to this one:我有一个类似于这个的 JSON 对象:

{
  "customers": [
    {
      "id": 1,
      "name": "bob",
      "orders": [{"id": 1, "customerId": 1, "itemId": 6}]
    },
    {
      "id": 2,
      "name": "jane",
      "orders": [{"id": 2, "customerId": 2, "itemId": 7}]
    }
  ]
}

I'd like to query it like....我想查询它像....

...odata/customers?$expand=orders&$filter=orders/any(order: order/itemId eq 6)

...and get... ……然后得到……

{
  "customers": [
    {
      "id": 1,
      "name": "bob",
      "orders": [{"id": 1, "customerId": 1, "itemId": 6}]
    },
    {
      "id": 2,
      "name": "jane",
      "orders": []
    }
  ]
}

but what I get is...但我得到的是......

{
  "customers": [
    {
      "id": 1,
      "name": "bob",
      "orders": [{"id": 1, "customerId": 1, "itemId": 6}]
    }
  ]
}

I want to get all the customers and I only want the filter to apply to the "orders".我想获得所有客户,我只想将过滤器应用于“订单”。

What can I do to get this result?我该怎么做才能得到这个结果?

Just got the same problem!刚刚遇到同样的问题! Solved by filtering my expand by the same condition in any().通过在 any() 中按相同条件过滤我的展开来解决。

applications?$expand=accounts($filter=idUser eq 5)&$filter=accounts/any(account: account/idUser eq 5)

Maybe to late but hope it will help someone else ;)也许为时已晚,但希望它会帮助别人;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM