OData未知函数'替换'

本文关键字:替换 未知 函数 OData | 更新日期: 2023-09-27 17:53:16

我无法使用odata获得替换函数,得到以下错误:"未知函数'replace'"

所以我在他们的文档中找到了示例url,当然同样的错误。http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=replace(CompanyName, '', '') eq 'AlfredsFutterkiste'

有替代的方法吗?

OData未知函数'替换'

按allowwedfunctions, V3的Web API还不允许替换

示例服务正在使用WCF数据服务,并且它需要将DataServiceBehavior上的AcceptReplaceFunctionInQuery设置为true以支持替换。默认为false。

一种方法是将indexof in与substring结合使用来进行替换,但这只在要替换的字符串只出现一次时才有效。参见下面的查询:

http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=indexof(CompanyName, ' ') ge 0 and concat(substring(CompanyName, 0, indexof(CompanyName, ' ')),substring(CompanyName, indexof(CompanyName, ' ') add 1, length(CompanyName))) eq 'AlfredsFutterkiste'

我尝试添加字符串。将OData替换为https://github.com/OData/WebApi/issues/1937,但显然根据Michael Pizzo:

我们实际上有意省略了string。替换,因为它是被识别为可能的DOS攻击面。使用字符串。取代,不良行为者可能会创建溢出的请求服务器。

在我们真正拥有安全之前,生活要容易得多…

该功能也不再出现在规格中。