在OData URI中使用过滤器时出错500

时间:2012-12-01 18:24:49

标签: asp.net-mvc asp.net-mvc-4 asp.net-web-api odata

当我使用简单的API时:/api/dashboard它完美无缺!

但是,我添加的任何过滤器都会返回以下错误!

API URI

/api/dashboard?$filter=(ProximoAtendimento%20gt%20datetime'2012-11-30'%20and%20ProximoAtendimento%20lt%20datetime'2012-12-02')

错误

{
    "Message": "An error has occurred.",
    "ExceptionMessage": "Method not found: 'Microsoft.Data.OData.Query.SemanticAst.ParameterQueryNode Microsoft.Data.OData.Query.SemanticAst.FilterQueryNode.get_Parameter()'.",
    "ExceptionType": "System.MissingMethodException",
    "StackTrace": "   at System.Web.Http.OData.Query.Expressions.FilterBinder.BindFilterQueryNode(FilterQueryNode filterNode)\r\n   at System.Web.Http.OData.Query.Expressions.FilterBinder.Bind(FilterQueryNode filterNode, Type filterType, IEdmModel model, IAssembliesResolver assembliesResolver, ODataQuerySettings querySettings)\r\n   at System.Web.Http.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)\r\n   at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\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)"
}

API控制器

[Queryable]
public IQueryable<Pessoa> get()
{
    return _repository.Query<Pessoa>();
}

套件版本

  1. Microsoft.AspNet.WebApi.OData - &gt; 0.2.0-α
  2. Microsoft.Data.Edm - &gt; 5.1.0
  3. Microsoft.Data.OData - &gt; 5.1.0
  4. Microsoft.Data.OData.Contrib - &gt; 5.1.0.51119
  5. System.Spatial - &gt; 5.1.0
  6. Microsoft.AspNet.WebApi - &gt; 4.0.20710.0
  7. Microsoft.AspNet.WebApi.Client - &gt; 4.1.0-α-120809
  8. Microsoft.AspNet.WebApi.Core - &gt; 4.0.20710.0
  9. Microsoft.AspNet.WebApi.OData - &gt; 0.2.0-α
  10. Microsoft.AspNet.WebApi.Web ... - &gt; 4.0.20710.0

1 个答案:

答案 0 :(得分:0)

MissingMethodExceptions通常是由不匹配的程序集版本引起的。在您的情况下,看起来您应该使用此NuGet包:

5.1.0.51016-rc2 for Microsoft.Data.OData.Contrib而不是5.1.0.51119。

请参阅:http://www.nuget.org/packages/microsoft.aspnet.webapi.odata