title: Use linq to filter by property of subcollection
body: <pre><code>class Store
  {
      public int ID { get; set; }
      public List&lt;AnnualData&gt; annualData { get; set; }
  }
  
  class AnnualData
  {
      public int Year { get; set; }
      public Dictionary&lt;string, double&gt; Data { get; set; }
  }
  </code></pre>
  
  <p>I need to get the requested stores and the requested years' data.  I can filter stores easily:</p>
  
  <pre><code>List&lt;int&gt; storeIDs = new List&lt;int&gt; {12, 13, 14};
  List&lt;Store&gt; stores = allData.Stores.Where(s =&gt; storeIDs.Contains(s.ID)).ToList();
  </code></pre>
  
  <p>But I can't figure out how to further filter by a list of years.</p>
  
  <pre><code>List&lt;int&gt; years = new List&lt;int&gt; {2012, 2013, 2014};
  stores = allData.Stores.Where(s =&gt; storeIDs.Contains(s.ID)).?????
  </code></pre>
  
  <p>Tried Any/All/Contains but I'm obviously not understanding Linq well enough. Thanks in advance.</p>
  
  <p><strong>Update after proposed solutions by Selmann &amp; Timothy</strong>
  Using your examples I still see all 3 years for store 1 in the output - I want to see only 2007 in t his case:</p>
  
  <pre><code>   static void Main(string[] args)
      {
          List&lt;Store&gt; allData = new List&lt;Store&gt; {                 
              new Store { ID = 1,
                          annualData = new List&lt;AnnualData&gt; {
                              new AnnualData {
                                  Year = 2006,
                                  Data = new Dictionary&lt;string, double&gt;{{"Value2006", 1.0}}
                              },
                              new AnnualData {
                                  Year = 2007,
                                  Data = new Dictionary&lt;string, double&gt;{{"Value2007", 1.1}}
                              },
                              new AnnualData {
                                  Year = 2008,
                                  Data = new Dictionary&lt;string, double&gt;{{"Value2008", 1.2}}
                              }
                          }
              }
          };
  
          List&lt;int&gt; storeIDs = new List&lt;int&gt; { 1 };
          List&lt;int&gt; years = new List&lt;int&gt; { 2007 };
  
          var stores = allData.Where(s =&gt; storeIDs.Contains(s.ID) &amp;&amp;
                                       s.annualData.Any(x =&gt; years.Contains(x.Year)));
  
          foreach (Store s in stores)
              foreach (AnnualData a in s.annualData)
                  Console.WriteLine(a.Year);
  
      }
  </code></pre>