OData $select not working on Web API

2019-07-17 15:10发布

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条回答
迷人小祖宗
2楼-- · 2019-07-17 15:46

'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.

查看更多
登录 后发表回答