title: .NetCore C# - Can LINQ Query operators be seperated by logic?
body: <p>Lets say I have six <code>LINQ queries</code>. Each query contains the operators that the previous query used and adds one more operator to the chain:</p>
  
  <pre><code>Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
   )
   .ToListAsync(); 
  
  Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          .Where(f =&gt; f.recordid == x)
   )
   .ToListAsync(); 
  
  Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          .Where(f =&gt; f.recordid == x)
          .Where(f =&gt; !StatusExceptionList.Contains(r.Status))
   )
   .ToListAsync(); 
  
  Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          .Where(f =&gt; f.recordid == x)
          .Where(f =&gt; !StatusExceptionList.Contains(r.Status))
          .OrderBy(f =&gt; f.date1)
   )
   .ToListAsync(); 
  
  Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          .Where(f =&gt; f.recordid == x)
          .Where(f =&gt; !StatusExceptionList.Contains(r.Status))
          .OrderBy(f =&gt; f.date1)
          .ThenBy(f =&gt; f.date2)
  )
  .ToListAsync(); 
  
  Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          .Where(f =&gt; f.recordid == x)
          .Where(f =&gt; !StatusExceptionList.Contains(r.Status))
          .OrderBy(f =&gt; f.date1)
          .ThenBy(f =&gt; f.date2)
          .ThenBy(f =&gt; f.recordid)
  )
  .ToListAsync(); 
  </code></pre>
  
  <p>I'd like to compact this down to one query, with logic weaved between the different linq operators, as this pseudocode shows, and this doesnt work at all. Ive googled around and not sure what to try next:</p>
  
  <pre><code>Foo = await
  (
      _context.Foo
          .Where(f =&gt; (Convert.ToDateTime(f.date1) - today).TotalDays &lt; 31)
          if (some logic)
          {
              .Where(f =&gt; f.recordid == x)
          }
          if (some different logic)
          {           
              .Where(f =&gt; !StatusExceptionList.Contains(r.Status))
          }
          if (some different logic)
          {
              .OrderBy(f =&gt; f.date1)
          }
          if (some different logic)
          {
              .ThenBy(f =&gt; f.date2)
          }
          if (some different logic)
          {
              .ThenBy(f =&gt; f.recordid)
          }
  )
  .ToListAsync(); 
  </code></pre>
  
  <p>Would anyone be able to point me in the right direction or tell me if i'm trying to go about this in the wrong way? Thanks a bunch!!!</p>