我支持OData的WebAPI 2.2服务。
我的控制器有一个返回IQuerable<Entity>
的操作,但即使我允许所有功能,我也无法使用$filter=substringof
功能。
[Authorize]
public class MyController : ODataController
{
[EnableQuery(AllowedFunctions=AllowedFunctions.All)]
public IQueryable<Entity> GetEntities()
{
return GetMyQueryable();
}
}
当我点击http://localhost:49844/Entities/?$filter=substringof('Queen',Name)
我收到错误,说不允许使用substringof。
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. An unknown function with name 'substringof' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.",
"innererror": {
"message": "An unknown function with name 'substringof' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.",
"type": "Microsoft.OData.Core.ODataException",
知道为什么我会看到这个错误吗?
答案 0 :(得分:47)
substringof()
是 V3 功能,而contains()
是 V4 功能。
尝试包含:
$filter=contains(Name,'Queen')