我正在使用需要支持 oData 的 MVC 4 创建一个 WebApi 应用程序。
我按照建议安装了包 Microsoft.AspNet.WebApi.OData (Install-Package Microsoft.AspNet.WebApi.OData -Pre),但是在过滤时 [例如:/api/cars?$filter=startswith(Name,'F') ] 我得到了例外:
{"Message":"An error has occurred.","ExceptionMessage":"Method not found: 'Int32 Microsoft.Data.OData.Query.SemanticAst.QueryNode.get_Kind()'.","ExceptionType":"System.MissingMethodException","StackTrace":" at System.Web.Http.OData.Query.Validators.FilterQueryValidator.ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.Validators.FilterQueryValidator.ValidateQueryNode(QueryNode node, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.QueryableAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"}
我错过了什么?