title: LINQ how to query if a value is between a list of ranges?
body: <p>Let's say I have a Person record in a database, and there's an Age field for the person.</p>
  
  <p>Now I have a page that allows me to filter for people in certain age ranges.</p>
  
  <p>For example, I can choose multiple range selections, such as "0-10", "11-20", "31-40".</p>
  
  <p>So in this case, I'd get back a list of people between 0 and 20, as well as 30 to 40, but not 21-30.</p>
  
  <p>I've taken the age ranges and populated a List of ranges that looks like this:</p>
  
  <pre><code>class AgeRange
  { 
       int Min { get; set; }
       int Max { get; set; }
  }
  
  List&lt;AgeRange&gt; ageRanges = GetAgeRanges();
  </code></pre>
  
  <p>I am using LINQ to SQL for my database access and queries, but I can't figure out how query the ranges.</p>
  
  <p>I want to do something like this, but of course, this won't work since I can't query my local values against the SQL values:</p>
  
  <pre><code>var query = from person in db.People 
              where ageRanges.Where(ages =&gt; person.Age &gt;= ages.Min &amp;&amp; person.Age &lt;= ages.Max).Any())
              select person;
  </code></pre>