简体   繁体   中英

OData $select not working on Web API

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM