简体   繁体   English

$expand 实体上的 SAP 网关 $filter

[英]SAP Gateway $filter on $expand Entity

I've seen two post about the URL convention, but my question is specific to the SAP's Gateway implementation for OData web services assuming.我看过两篇关于 URL 约定的帖子,但我的问题是针对 OData Web 服务假设的 SAP 网关实现的。 When trying to use $filter in combination with $expand we get the error message:当尝试将$filter$expand结合使用时,我们会收到错误消息:

Left hand expression of memberaccess operation has wrong cardinality

Assuming I have two simple entities:假设我有两个简单的实体:

Foo
 * Key
 - Value

Bar
 * Key
 * Id
 - Value

Foo has a 1:n association to Bar . Foo 与Bar有 1:n 关联。 The following URL works as intended.以下 URL 按预期工作。

/sap/opu/odata/sap/ZTEST_SRV/Foo?$expand=Bar

As does就像

/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10&$expand=Bar

When trying to using $filter on entity Bar property Id we get the error message.尝试在实体Bar属性Id上使用$filter ,我们收到错误消息。

/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10 and Bar/Id gt 2&$expand=Bar

Is it possible to use a $filter in this way with SAP?是否可以在 SAP 中以这种方式使用$filter Related articles below.相关文章如下。

ODATA / SAP Gateway: About Query with $filter and $expand simultaneously ODATA / SAP Gateway:关于同时使用 $filter 和 $expand 进行查询

Filter on Expanded entities in OData 筛选 OData 中的扩展实体

I am also facing similar problems, there is this sap note: https://apps.support.sap.com/sap/support/knowledge/en/3008698我也面临类似的问题,有这个sap说明: https : //apps.support.sap.com/sap/support/knowledge/en/3008698

Copy of the note details:笔记详细信息的副本:


BEGIN OF NOTE开始注意


Symptom症状

After adding a filter添加过滤器后

$filter = To_Employees/Name eq 'Hugo' to an Odata service, there is an error: $filter = To_Employees/Name eq 'Hugo' 到 Odata 服务,出现错误:

"Left hand expression of memberaccess operator has wrong cardinality (to many not allowed)" “memberaccess 运算符的左手表达式具有错误的基数(许多不允许)”


Environment环境

SAP_GWFND 750 SAP_GWFND 750


Reproducing the Issue重现问题

Access the odata service: /sap/opu/odata/sap/API_XXX_SRV/Orgnization$select=Orgnization,to_Employees/Name&$expand=to_Employees&$filter=to_Employees/Name eq 'Hugo' 
There is an error: "Left hand expression of memberaccess operator has wrong cardinality (to many not allowed)"

Cause原因

"Left hand expression of memberaccess operator has wrong cardinality (to many not allowed)" indicates that "to_Employees"is a to-many navigation, and this is not supported in combination with a filter expression (eg “memberaccess 运算符的左手表达式具有错误的基数(不允许很多)”表示“to_Employees”是一对多导航,并且不支持与过滤器表达式结合使用(例如

$filter = To_Employees/Name eq 'Hugo', $filter = To_Employees/Name eq 'Hugo',

when "To_Employees" points to more than one employee ).当“To_Employees”指向多个员工时)。

Therefore, the whole request is invalid.因此,整个请求无效。


Resolution分辨率

Remove the filter, do not combine to many results with filter eq删除过滤器,不要用过滤器 eq 组合到很多结果


END OF NOTE笔记结束

I don't like the solution presented :)我不喜欢提出的解决方案:)

The workaround solution I have implemented was to create an entity which has cardinality 1:1 just for filtering.我实施的解决方法是创建一个基数为 1:1 的实体,仅用于过滤。 In your example, I assume you need the cardinaliy of the relationship from Foo to Bar to be 1:n in order to be able to receive multiple Bar records for each Foo found.在您的示例中,我假设您需要从 Foo 到 Bar 的关系的基数为 1:n,以便能够为找到的每个 Foo 接收多个 Bar 记录。 If the relationship Foo to Bar is 1:1, you can simply change the cardinality and you are good to go.如果 Foo 与 Bar 的关系为 1:1,您只需更改基数即可。 If you need cardinality 1:n, you may create an entity like BarFilter which is related to Foo with 1:1 cardinality.如果您需要基数 1:n,您可以创建一个像 BarFilter 这样的实体,它与具有 1:1 基数的 Foo 相关。 Then you would be able to execute this request without errors and can receive the filters to make the corresponding query on your backend system.然后,您将能够毫无错误地执行此请求,并且可以接收过滤器以在您的后端系统上进行相应的查询。 The request would be something like:请求将类似于:

New simple entity:新的简单实体:

BarFilter条形过滤器

  • Key钥匙
  • Id身份证
  • Value价值

Foo has a 1:1 association to new entity BarFilter. Foo 与新实体 BarFilter 具有 1:1 关联。

Request:请求:

/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10 and BarFilter/Id gt 2&$expand=Bar /sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10 and BarFilter/Id gt 2&$expand=Bar

I hope this is clear and that it helps you.我希望这很清楚并且对您有所帮助。 I am very interested in this topic so if you find something interesting, please share it.我对这个话题很感兴趣,所以如果你发现一些有趣的东西,请分享它。

Have a nice weekend.祝你周末愉快。

Cheers干杯

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

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