I have a working (simplified) ODataController with the following method.
public class MyTypeController : ODataController { [HttpGet] [EnableQuery] [ODataRoute("myTypes")] public IQueryable<MyType> GetMyTypes(ODataQueryOptions<MyType> options) { return _repo.myResultsAsQueryable(); } }
I would like to be able to call this method from the server, and for this I need to create an instance of ODataQueryOptions , which requires an ODataQueryContext .
There are examples of how to do this (for example, here and here ), but they all seem to refer to a previous version of OData. The ODataQueryContext constructor currently requires a third argument ( ODataPath path), which is not addressed in any of the examples I can find.
Edit: @snow_FFFFFF, Here is some other context ... I understand that I can just use the OData endpoint via HttpClient, but I would like to interact directly with IQueryable, as you say.
The problem is that the application I'm working on allows users to create filters (for example, complex search engines) that can be saved and later called by other users. From the JS client, they simply search for the filter by id and issue a request to the OData endpoint with the filter applied to the query string. This works very well on the client side, but I would like to be able to do something similar on the server side.
This is what I would like to do, but how can I instantiate an ODataPath argument?
public IQueryable<MyType> FilterMyTypes(int filterID) { // lookup filter by filterID from db... filter = "$filter=Status eq 1"; // for example... ODataPath path = // but how can I get the path!!! new ODataQueryContext(edmModel, typeof(MyType), path); var uri = new HttpRequestMessage(HttpMethod.Get, "http://localhost:56339/mytypes?" + filter); var opts = new ODataQueryOptions<MyType>(ctx, uri); var results = new MyTypeController().GetMyTypes(opts); }
Another application of this would be support for dynamic grouping, as shown below:
[HttpGet] [Route("myTypes/{filterID:int}/groupby/{groupByFieldName}")] public IHttpActionResult GroupMyTypes(int filterID, string groupByFieldName) {