我正在使用需要支持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)"}
我缺少什么?
答案 0 :(得分:1)
导致此问题的基础OData库版本存在二进制不兼容性。我强烈建议使用我们的夜间版本。只需在包管理器控制台中使用此命令:
Install-Package Microsoft.AspNet.WebApi.OData -Source http://www.myget.org/F/aspnetwebstacknightly/ -Pre
这也将为您提供一个Web API OData支持版本,它更接近最终版本位。