0
我正在使用ASP.NET WEB API Odata庫。如果我在我的調用中使用substringof,並且值爲null,則失敗。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庫的問題。有什麼辦法可以預防它嗎?