title: Building a LINQ query programmatically without local variables tricking me
body: <p>Assume my objects are in perfect working order (i.e. TDD makes me think they work).</p>
  
  <p>I have a list that I create like this (except indented properly):</p>
  
  <pre><code>var result = from v in vendors
               from p in v.Products
               orderby p.Name
               select p;
  </code></pre>
  
  <p>This works - I get all products from all vendors.</p>
  
  <p>Now I have a list of conditions, built up at runtime by the user. Let's apply them:</p>
  
  <pre><code>foreach (Attribute a in requiredAttributes)
  {
      result = result.Where(p =&gt; p.Attributes.Contains(a));
  }
  </code></pre>
  
  <p>This may be primitive, but I thought it'd work. However, after this foreach loop is finished, when you enumerate "result" it will contain all products that has the LAST Attribute of the requiredAttributes collection in it's Attributes property (also a collection).</p>
  
  <p>To me, this smells like "a" is overwritten somewhere with each trip trough the loop, and only the last one applies.</p>
  
  <p>Short of somehow writing an extension method to IEnumerable called ContainsAll(IEnumerable) or something to that effect, how can I achieve what I want, which is basically a logical AND, giving me only those products that has ALL the required attributes?</p>