Monday 15 July 2013

web api - Web API 2.2 - OData v4 ODataQueryOptions.applyTo() returning null when $select or $expand present? -


I have setup a Web API 2.2 Odita Controller, such as I can manually process my Odata options ( Meaning [without enabled] and / or an ODataQueryOptions parameter) I have gone into a bug that looks like following the following code:

  public IHttpActionResult GetEmployees () {// Asked Get known items (in this case just an in-store list query The went to) IQueryable & lt; Employee & gt; Employees = _Employees.AsQueryable (); // query Get the requested url without string (String NewURI = other ways to make a request) Request. request. AbsoluteURI; If (! String.IsNullOrEmpty (Request.RequestUri.Query)) {newUri = newUri.Replace (Request.RequestUri.Query, ""); } // Add custom Odata Quickstring (this is for example purposes) newUri = String.Format ("{0}? $ Skip = {1} and $ top = {2}", Neweur, 1, 1); // Create new HTTPExt message from updated URI. HTTP & First Message NewAreview = New HTTPExt Message (Request Method, New Yury); / / ODataQueryContext based initial request (ODataQueryOptions required to create) ODataQueryContext newContext = New ODataQueryContext (Request.ODataProperties (.) Model, type (employee), Request.ODataProperties (. Path); // Create new OdataCounting new reference and new request ODataQueryOptions & lt; Employee & gt; NewOptions = New ODataQueryOptions & lt; Employee & gt; (NewContext, newRequest); // Queryable items apply new ODataQueryOptions to employees = newOptions.ApplyTo (employees) as IQueryable & lt; Employee & gt ;; // Returned list (will be serialized by the Odata format) Ok (employees. Technologist); }  

which works 100%, however this adds an extension of $ $ or $ such as this:

  newUri = String.Format ("{0 }? $ Skip = {1} and $ top = {2} and $ extension = projects ", Newyouri, 1, 1);  

  IQueryable from employee = newOptions.ApplyTo (employees) & lt; Employee & gt ;;  

That has forced me to create two separate oDDTV, IQueryable to apply one (without any $ selection or $ extension), and only with the other To select $ $ / $ the selection is selected to allocate to SelectExpandClause.DodPortitions (). Select Expanded Clauses

I do not understand why a blank return is happening. The main purpose behind this code allows for more control over the processing of oatata when the units work with ORM other than the framework. So in reality I will eliminate overriding (or manually to process the expression tree manually), but this particular example looks like a bug to me.

Can anyone give me some information on this? Maybe there is something that I'm missing.

(pick up my comment for an answer)

Because you Really obtain from Apply (once you choose $ or add $ extension)

  System.Web.odata.Query.Expressions.SelectExpandBinder.SelectAllAndExpand & lt; Employe E & gt;  

Which, of course, can not be inserted into the IQueryable, therefore zero.

Why not add the EnableQuery attribute, and an IQueryable return (instead of ToList)?


No comments:

Post a Comment