简体   繁体   English

使用自定义属性数组( $expand )过滤 oData 并将 $filter 用于特定属性

[英]Filter oData with array of custom attribute ( $expand ) and use $filter for a specific attribute

With this structure of the oData v2 result from a GetEntitySet (JSON Format)使用来自 GetEntitySet(JSON 格式)的 oData v2 结果的这种结构

{
d: {
__count: "3215",
result : [
 {
   City    : 'NewYork',
   Country : 'USA',
   CustomAttributeData : {
     results : [ 
      {   Name: "custom1",
          Value: "20220707"
      },
      {   Name: "custom2",
          Value: "20220710"
      },
      {   Name: "custom3",
          Value: "20220713"
      }
    ]
  }
 },
 {
   City    : 'Rome',
   Country : 'ITALY',
   CustomAttributeData : {
     results : [ 
      {   Name: "custom1",
          Value: "20220702"
      },
      {   Name: "custom2",
          Value: "20220710"
      },
      {   Name: "custom3",
          Value: "20220710"
      }
    ]
  }
 },
 {
   City    : 'Tokyo',
   Country : 'JAPAN',
   CustomAttributeData : {
     results : [ 
      {   Name: "custom1",
          Value: "20220710"
      },
      {   Name: "custom2",
          Value: "20220711"
      },
      {   Name: "custom3",
          Value: "20220710"
      }
    ]
  }
 }
],
}
}
....

]

I want to filter all the cities with the CustomAttributeData custom2=20220710 (all but not Tokyo).我想用 CustomAttributeData custom2=20220710 过滤所有城市(除了东京之外)。 What is the correct uri ?什么是正确的 uri?

https://xxxxxx?$expand=CustomAttributeData$filter=CustomAttributeData/Value eq '20220710'

This one is of course wrong because consider Tokyo too.这当然是错误的,因为也考虑到东京。

Someone can help me?有人可以帮助我吗?

With OData V2, it's not possible.使用 OData V2,这是不可能的。 You'll need to use the any lambda operator * for your filter which is available only in OData V4.您需要对过滤器使用any lambda 运算符*,该过滤器仅在 OData V4 中可用。


* See also this SAP Developer video section which explains any and all operators for OData V4 filters. * 另请参阅此SAP Developer 视频部分,该部分解释all any符。

You can filter out Tokyo by using ne operator in $filter query.您可以在$filter查询中使用ne运算符过滤掉东京。

$filter=City ne 'Tokyo'

Added to your query添加到您的查询

https://xxxxxx?$expand=CustomAttributeData&$filter=City ne 'Tokyo' and CustomAttributeData/Value eq '20220710'

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

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