title: Using a conditional if statement in a Linq query
body: <p>I'm trying to write a linq query that uses an if statement. </p>
  
  <p>In the code below I'm searching for matches of </p>
  
  <p>n.SAU_ID = sau.SAUID where</p>
  
  <p>ReportingPeriod column contains "Oct1" then
   FiscalYear - aprYearDiff = sau.SAUYearCode. </p>
  
  <p>Else</p>
  
  <p>FiscalYear - octYearDiff = sau.SAUYearCode. </p>
  
  <p>My code is only giving matches for the SAUID and "Oct1".</p>
  
  <p>What code is needed to implement theese statements?</p>
  
  <pre><code>    int FiscalYear = 2014;       
  
      List&lt;String&gt; addtowns = new List&lt;string&gt;();
  
      List&lt;Stage_Reorg&gt; reorg = _entities.Stage_Reorg.ToList();
  
      int aprYearDiff = 2;
      int octYearDiff = 1;
  
      foreach (var sau in reorg)
      {
          addtowns.AddRange(_entities.Stage_EPSSubsidySADCSDTown
          .Where(n =&gt; n.SAU_ID == sau.SAUID 
              &amp;&amp; (n.ReportingPeriod == "Oct1" 
              ? (FiscalYear - aprYearDiff) == sau.SAUYearCode 
              : (FiscalYear - octYearDiff) == sau.SAUYearCode))
          .Select(n =&gt;  n.TownCode ));
      }
  </code></pre>