OData $select not working on Web API

天涯浪子 提交于 2019-12-14 02:06:18

问题


I'm trying to use OData to return a smaller, paginated result set from my web API. I'm modifying a large, existing API so I would like to be able to do this for only this one controller and method, preferably without using the extensive 'Microsoft ASP.NET Web API OData' package from NuGet, EdmModels, etc..

I've got $top and $skip working fine in my method below, but my $selects are being ignored.

My method:

    [Queryable(AllowedQueryOptions = System.Web.Http.OData.Query.AllowedQueryOptions.Select | System.Web.Http.OData.Query.AllowedQueryOptions.Top | System.Web.Http.OData.Query.AllowedQueryOptions.Skip )]
[HttpGet]
public HttpResponseMessage GetByType(OrganizationType type) {
    var results = _service.List(type);
    return(Request.CreateResponse<IQueryable<OrganizationModel>>(results.Any() ? HttpStatusCode.OK : HttpStatusCode.NotFound, results.AsQueryable<OrganizationModel>()));
  }
}

Any ideas why it's ignoring $select?


回答1:


'Microsoft ASP.NET Web API OData' 4.0.30506 package doesn't have the $select and $expand support. To get $select and $expand support, you have to upgrade to one of our latest packages. 5.0.0-beta2 should work. Optionally, you can try our nightly builds as well to get all the latest features.



来源:https://stackoverflow.com/questions/17617946/odata-select-not-working-on-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!