title: Build up IQueryable based on method parameters
body: <p>I have an API method similar to the below. </p>
  
  <p>Is it possible to append the IQueryable so the final query has a list of items to execute a where statement or should I use the SqlQuery property and build up a raw SQL string.</p>
  
  <pre><code>    public IEnumerable&lt;Message&gt; GetMessagesFromApi(DateTime? dateFrom = null, DateTime? dateTo = null, int flag = -1, int messageType = 1, bool media =false)
      {
          if (dateFrom == null)
              dateFrom = DateTime.MinValue;
  
          if (dateTo == null)
              dateTo = DateTime.MaxValue;
  
          IQueryable&lt;Message&gt; query = null;
  
  
          query = db.Messages.Where(x =&gt; x.Created &gt;= dateFrom &amp;&amp; x.Created &lt;= dateTo);
  
  
          if (flag &gt;= 0)
          {
              //Append the where statement on dates to now include Flag
              query = query.Where(x =&gt; x.Flag == flag);
          }
  
         //Here it should execute against Where date &gt;= and date &lt;= and flag = 1
      }
  </code></pre>