title: Search criteria and NULL
body: <p>I have been using the following method pattern in my Web API for searching entities given a set of criteria:</p>
  
  <pre><code>public IEnumerable&lt;Employee&gt; Search(SearchCriteria searchCriteria)
  {
      var employees = _dbContext.Employees;
  
      if(searchCriteria.Age.HasValue)
      {
          employees = employees.Where(e =&gt; e.Age == searchCriteria.Age.Value);
      }
  
      if(searchCriteria...)
      {
          employees = employees.Where(e =&gt; ...);
      }
  
      return employees;
  }
  </code></pre>
  
  <p>If a search criterion is not specified, then the property on the SearchCriteria object will be <code>null</code> and I simply do not filter based on this criterion. If it is specified, then it will have a value, and it is used for filtering.</p>
  
  <p>The problem, from a design perspective, is that if I actually want the <code>employees</code> that do not have an age, I simply cannot do it this way, since I use <code>null</code> to determine whether or not I will use the given criterion.</p>
  
  <p>What other approach should I look into in order to emcompass both cases?</p>
  
  <p>Perhaps looking at the URI instead of letting Web API do the object mapping, I could determine whether or not the criterion was actually present?</p>
  
  <pre><code>mysite.com/api/employee?keyword=a&amp;age=null
  </code></pre>
  
  <p>vs</p>
  
  <pre><code>mysite.com/api/employee?keyword=a
  </code></pre>