title: Linq query with a Conditional WHERE Clause
body: <p>I am new to LINQ so apologises upfront </p>
  
  <p>I have the following Linq query :- </p>
  
  <pre><code>var OrdersByBranches =
      from a in AllOrders
      join b in AllBranchKeys
          on a.BranchKey equals b.BranchKey
      orderby a.Date
      group a by new { a.Date, a.paymentMethod } into BranchOrderGrouped
      select new
      {
          BranchOrderGrouped.Key.Date,
          CurrencyAmount = BranchOrderGrouped.Sum(a =&gt;
          a.CurrencyAmount),
          BranchOrderGrouped.Key.paymentMethod
      };
  </code></pre>
  
  <p>I need to include a where clause in the above query ... only if a variable called 
  BranchKeySelected is  ""</p>
  
  <p>I have tried using an If Else statement and have the same above query duplicated with 
  one containing a where clause and one NOT. ...But When I do this .. then OrdersByBranches
  is NOT available outside of the IF Statement </p>
  
  <p>Would be grateful for any help</p>
  
  <p>Regards</p>
  
  <p>Ghost</p>