title: Creating a composite condition using anonymous filter method
body: <p>I am trying to edit a search tool using linq, </p>
  
  <p>What I like a filter in where clause is (ItemNumber == X AND ( StatementStatus == SatusA Or StatementStatus == StatusB ) )</p>
  
  <p>But right now, it is like:</p>
  
  <p>What I like a filter in where clause is (ItemNumber == X AND StatementStatus == SatusA Or StatementStatus == StatusB )</p>
  
  <p>as AND has higher operational priority over OR the result is not what I want. :)
  Could you please help?</p>
  
  <pre><code>using (var ctx = new MyContext())    {
      Func&lt;Statement, bool&gt; filter = null;
  
      if (!string.IsNullOrEmpty(request.ItemNumber))
          filter = new Func&lt;Statement, bool&gt;(s =&gt; s.StatementDetails.Any(sd =&gt; sd.ItemNumber == request.ItemNumber));
  
      if (request.StatusA)
          filter = filter == null ? new Func&lt;Statement, bool&gt;(s =&gt; s.StatementStatus == StatementStatusType.StatusA) : 
              filter.And(s =&gt; s.StatementStatus == StatementStatusType.StatusA);
  
      if (request.StatusB)
          filter = filter == null ? new Func&lt;Statement, bool&gt;(s =&gt; s.StatementStatus == StatementStatusType.StatusB) :
              filter.Or(s =&gt; s.StatementStatus == StatementStatusType.StatusB);
  
      var results = ctx.Statements
          .Include("StatementDetails")
          .Include("StatementDetails.Entry")
          .Where(filter)
          .Take(100)
          .Select(s =&gt; new StatementSearchResultDTO{ ....
          }
  }
  </code></pre>
  
  <p></p>