我看过两篇关于 URL 约定的帖子,但我的问题是针对 OData Web 服务假设的 SAP 网关实现的。尝试$filter与 with 结合使用时,$expand我们收到错误消息:
Left hand expression of memberaccess operation has wrong cardinality
Run Code Online (Sandbox Code Playgroud)
假设我有两个简单的实体:
Foo
* Key
- Value
Bar
* Key
* Id
- Value
Run Code Online (Sandbox Code Playgroud)
Foo 与 1:n 关联Bar。以下 URL 按预期工作。
/sap/opu/odata/sap/ZTEST_SRV/Foo?$expand=Bar
Run Code Online (Sandbox Code Playgroud)
就像
/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10&$expand=Bar
Run Code Online (Sandbox Code Playgroud)
尝试$filter在实体Bar属性上使用时,Id我们收到错误消息。
/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10 and Bar/Id gt 2&$expand=Bar
Run Code Online (Sandbox Code Playgroud)
是否可以$filter在 SAP 中以这种方式使用 a ?相关文章如下。
小智 2
我也面临类似的问题,有这个sap说明: https://apps.support.sap.com/sap/support/knowledge/en/3008698
注释详细信息的副本:
添加过滤器后
$filter = To_Employees/Name eq 'Hugo' 到 Odata 服务,出现错误:
“memberaccess 运算符的左手表达式具有错误的基数(许多不允许)”
SAP_GWFND 750
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)"
Run Code Online (Sandbox Code Playgroud)
“memberaccess 运算符的左手表达式具有错误的基数(不允许多个)”表示“to_Employees”是一个对多导航,并且不支持与过滤表达式结合使用(例如
$filter = To_Employees/姓名 eq 'Hugo',
当“To_Employees”指向多名员工时)。
因此,整个请求无效。
删除过滤器,不要使用过滤器 eq 合并多个结果
我不喜欢所提出的解决方案:)
我实施的解决方案是创建一个基数为 1:1 的实体,仅用于过滤。在您的示例中,我假设您需要从 Foo 到 Bar 的关系基数为 1:n,以便能够接收找到的每个 Foo 的多个 Bar 记录。如果 Foo 与 Bar 的关系是 1:1,您只需更改基数即可。如果您需要基数 1:n,您可以创建一个像 BarFilter 这样的实体,它与 Foo 具有 1:1 基数相关。然后您将能够正确执行此请求,并可以接收过滤器以在后端系统上进行相应的查询。该请求类似于:
新的简单实体:
条形过滤器
Foo 与新实体 BarFilter 具有 1:1 关联。
要求:
/sap/opu/odata/sap/ZTEST_SRV/Foo?$filter=Key gt 10 和 BarFilter/Id gt 2&$expand=Bar
我希望这很清楚并且对您有所帮助。我对这个话题很感兴趣,所以如果你发现一些有趣的东西,请分享。
祝你周末愉快。
干杯
| 归档时间: |
|
| 查看次数: |
5980 次 |
| 最近记录: |