title: LINQ WHERE clause using if statements
body: <p>I am using c#.net</p>
  
  <p>I have two textboxes which if !empty need to be part of a WHERE clause within a LINQ query.</p>
  
  <p>Here is my code </p>
  
  <pre><code>var result = from a in xxxx select a;
  
  if(!string.IsNullOrEmpty(personName))
  {
      return result.Where(a &gt;= a.forename.Contains(personName) || a.surname.Contains(personName)     
  }
  else if(!string.IsNullOrEmpty(dateFrom))
  {
      return result.Where(a &gt;= a.appStartDateTime &gt;= dateFrom.Date)
  }
  else if(!string.IsNullOrEmpty(personName) &amp;&amp; !string.IsNullOrEmpty(dateFrom))
  {
      return result.Where(a &gt;= a.forename.Contains(personName) || a.surname.Contains(personName) &amp;&amp;   a.appStartDateTime &gt;= dateFrom.Date);
  }
  </code></pre>
  
  <p>I thought this would work but it doesn't like the .Where and I cant access the 'a' for example a.forename (The name 'a' does not exist in the current context)</p>
  
  <p>What am I going wrong, or can this not actually be done?</p>
  
  <p>Thanks in advance for any help.</p>
  
  <p>Clare</p>