title: Linq syntax for chaining query combinations
body: <p>I have a few situations where I have combinations of selections and need to filter data (using EF in this case) based on what's selected. Is there cleaner way of writing the following rather than listing all of the combinations?</p>
  
  <p>My initial attempt below seems overly complicated especially if the combinations grow any larger.</p>
  
  <pre><code>DateTime today = DateTime.Now.Date;
  DateTime yesterday = today.AddDays(-1);
  DateTime tomorrow = today.AddDays(1);
  
  var query = db.Products.AsQueryable();
  if (userSettings.DisplayYesterday &amp;&amp; userSettings.DisplayToday &amp;&amp; userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == yesterday || DbFunctions.TruncateTime(x.ListedTime) == today || DbFunctions.TruncateTime(x.ListedTime) == tomorrow);
  }
  else if (!userSettings.DisplayYesterday &amp;&amp; userSettings.DisplayToday &amp;&amp; userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == today || DbFunctions.TruncateTime(x.ListedTime) == tomorrow);
  }
  else if (userSettings.DisplayYesterday &amp;&amp; !userSettings.DisplayToday &amp;&amp; userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == yesterday || DbFunctions.TruncateTime(x.ListedTime) == tomorrow);
  }
  else if (userSettings.DisplayYesterday &amp;&amp; userSettings.DisplayToday &amp;&amp; !userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == yesterday || DbFunctions.TruncateTime(x.ListedTime) == today);
  }
  else if (!userSettings.DisplayYesterday &amp;&amp; !userSettings.DisplayToday &amp;&amp; userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == tomorrow);
  }
  else if (!userSettings.DisplayYesterday &amp;&amp; userSettings.DisplayToday &amp;&amp; !userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == today);
  }
  else if (userSettings.DisplayYesterday &amp;&amp; !userSettings.DisplayToday &amp;&amp; !userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == yesterday);
  }
  else if (userSettings.DisplayYesterday &amp;&amp; !userSettings.DisplayToday &amp;&amp; !userSettings.DisplayTomorrow)
  {
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == yesterday);
  }
  else if (!userSettings.DisplayYesterday &amp;&amp; !userSettings.DisplayToday &amp;&amp; !userSettings.DisplayTomorrow)
  {
      //  If nothing is selected then default to today
      query = query.Where(x =&gt; DbFunctions.TruncateTime(x.ListedTime) == today);
  }
  
  List&lt;Products&gt; productList = await query.ToListAsync();
  </code></pre>