title: Generic filtering on query string parameters
body: <p>I'm looking to convert our current API architecture to a more generic query-able structure that doesn't require us to hard card each possible parameter and build up a custom query. Here is an example of what our current architecture looks like,</p>
  
  <pre><code>[HttpGet]
  [Route("Companies/{id:int}/Implementations/Tasks")]
  public async Task&lt;IApiResponse&lt;List&lt;CompanyIPTDTO&gt;&gt;&gt; GetCompanyIPTs(int? id = null, 
  int? taskId = null, int? completedById = null, DateTime? dateCompletedStart = null, 
  DateTime? dateCompletedEnd = null, int page = 1, int? pageSize = null)
  {
      // Instantiate generic query
      Expression&lt;Func&lt;CompanyIPT, bool&gt;&gt; query = null;
  
      // Check parameters and build the lambda query
      // Check if the parameter is given and if the query field is already filled so as to either set or add a query
      if (id != null &amp;&amp; query != null) query = query.And(t =&gt; t.CompanyID == id);
      else if (id != null &amp;&amp; query == null) query = t =&gt; t.CompanyID == id;
  
      if (taskId != null &amp;&amp; query != null) query = query.And(t =&gt; t.ProcessTaskID == taskId);
      else if (taskId != null &amp;&amp; query == null) query = t =&gt; t.ProcessTaskID == taskId;
  
      if (completedById != null &amp;&amp; query != null) query = query.And(t =&gt; t.CompletedByID == completedById);
      else if (completedById != null &amp;&amp; query == null) query = t =&gt; t.CompletedByID == completedById;
  
      if ((dateCompletedStart != null &amp;&amp; dateCompletedEnd != null) &amp;&amp; query != null) query = query.And(a =&gt; a.DateCompleted &gt;= dateCompletedStart &amp;&amp; a.DateCompleted &lt;= dateCompletedEnd);
      else if ((dateCompletedStart != null &amp;&amp; dateCompletedEnd != null) &amp;&amp; query == null) query = a =&gt; a.DateCompleted &gt;= dateCompletedStart &amp;&amp; a.DateCompleted &lt;= dateCompletedEnd;
  
      // Execute the GET with the appended query and paging information
      var result = _uow.CompanyIPTRepository.List(filter: query, page: page, pageSize: pageSize);
      int totalPossibleRecords = _uow.CompanyIPTRepository.GetTotalRecords(filter: query);
  
      return new ApiSuccessResponse&lt;List&lt;CompanyIPTDTO&gt;&gt;(HttpStatusCode.OK, result.Select(x =&gt; Mapper.Map&lt;CompanyIPTDTO&gt;(x)).ToList(), result.Count(), Request.RequestUri, totalPossibleRecords, pageSize);
  }
  </code></pre>
  
  <p>And as you can see this gets very cumbersome for a large API on every get request to have to customize the query checks. I assume there must be some way to do this generically based on a query string parameter that comes in. For example in this case I would love to see a request come in that looks like,</p>
  
  <pre><code>https://www.example.com/api/Companies/15/Implementations/Tasks?q=[completedById=5,dateCompletedStart=1/15/18,dateCompletedEnd=1/17/18]
  </code></pre>
  
  <p>And after coming in like this I assume we could build something that uses Reflection to look at the object and verify these fields exist and build up a generic query to hit our DB?</p>
  
  <p>Anyone know where to point us in the right direction?</p>