title: Conditional Multiple Fields Searching and Filtering in LINQ
body: <p>Assuming that we have the following table:</p>
  
  <pre><code>Person:
    PersonID,
    Name,
    Age,
    Gender
  </code></pre>
  
  <p>And we are providing a search function that allows users to search the table according to the name <strong>and/or</strong> the age.</p>
  
  <p>The tricky part in writing the SQL ( or LINQ) query is that the users can choose to search for both field, or any one field, or no field. If he wants to search for all then he would just have to leave the textbox blank. </p>
  
  <p>The logic to do this can be written as follows:</p>
  
  <pre><code>var p;
  if(Name_TextBox=='')
  {
     p=from row in person
          select row ;
  }
  else 
  {
    p= from row in person
        where row.Name=Name_TextBox
          select row ;
  }
  // repeat the same for age
  </code></pre>
  
  <p>Now after a while the code gets very long and messy... How can I compress the above into a single query with <strong>no if-else</strong>?</p>