title: ASP .NET MVC 4 WebApi: Manually handle OData queries
body: <p>I have a Web Service made using the <strong>WebAPI</strong> provided by ASP .NET MVC 4.
  I know that the layer on top of which WebAPI works automatically handles <strong>OData Queries</strong> (such as <code>$filter</code>, <code>$top</code>, <code>$skip</code>), but what if I want to handle the filtering by myself?</p>
  
  <p><a href="https://i.stack.imgur.com/Bgv8W.jpg" rel="noreferrer">I don't simply return data from my database</a>, but I have another layer which adds some properties, makes some conversions etc. So querying ALL of my data, converting them and returning them to the WebAPI class for OData filtering isn't just good enough. It's of course terribly slow, and generally a crappy idea.</p>
  
  <p>So is there a way to <strong>propagate the OData query parameters</strong> from my WebAPI entry point to the functions I call to get and convert the data?</p>
  
  <p>For example, a GET to <code>/api/people?$skip=10&amp;$top=10</code> would call on the server:</p>
  
  <pre><code>public IQueryable&lt;Person&gt; get() {
      return PersonService.get(SomethingAboutCurrentRequest.CurrentOData);
  }
  </code></pre>
  
  <p>And in <code>PersonService</code>:</p>
  
  <pre><code>public IQueryable&lt;Person&gt; getPeople(var ODataQueries) {
      IQueryable&lt;ServerSidePerson&gt; serverPeople = from p in dbContext.ServerSidePerson select p;
      // Make the OData queries
      // Skip
      serverPeople = serverPeople.Skip(ODataQueries.Skip);
      // Take
      serverPeople = serverPeople.Take(ODataQueries.Take);
      // And so on
      // ...
  
      // Then, convert them
      IQueryable&lt;Person&gt; people = Converter.convertPersonList(serverPeople);
      return people;
  }
  </code></pre>