我正在使用ASP.NET WEB API Odata库。如果我在调用中使用 substringof 并且值为 null 则失败。
我传递的URI是: ... odata/MyEntity()?$filter=substringof(null,Name)
...
结果是:
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code />
<m:message xml:lang="en-US">The query specified in the URI is not valid.</m:message>
<m:innererror>
<m:message>The 'substringof' function cannot be applied to an enumeration-typed argument.</m:message>
<m:type>Microsoft.Data.OData.ODataException</m:type>
<m:stacktrace> at System.Web.Http.OData.Query.Expressions.FilterBinder.ValidateAllStringArguments(String functionName, Expression[] arguments)
at System.Web.Http.OData.Query.Expressions.FilterBinder.BindSubstringOf(SingleValueFunctionCallNode node)
at System.Web.Http.OData.Query.Expressions.FilterBinder.BindSingleValueFunctionCallNode(SingleValueFunctionCallNode node)
at System.Web.Http.OData.Query.Expressions.FilterBinder.Bind(QueryNode node)
at System.Web.Http.OData.Query.Expressions.FilterBinder.BindFilterClause(FilterClause filterClause, Type filterType)
at System.Web.Http.OData.Query.Expressions.FilterBinder.Bind(FilterClause filterClause, Type filterType, IEdmModel model, IAssembliesResolver assembliesResolver, ODataQuerySettings querySettings)
at System.Web.Http.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)
at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at System.Web.Http.QueryableAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)</m:stacktrace>
</m:innererror>
</m:error>
所以这似乎是 WEB API Odata 库中的一个问题。有什么办法可以预防吗?