title: LINQ select new KeyValuePair<T,List<T2>>
body: <p>I have a LINQ query like this:
  Two lists linked through Entity Framework Navigation Properties (Both Entities have a Many-To-Many Relationship)</p>
  
  <p>I'd like to convert this:</p>
  
  <pre><code>var query = (from a in listA 
               from b in a.ListB
               select new {T1=a, T2=b}
  </code></pre>
  
  <p>To something like this:</p>
  
  <pre><code>var query = (from a in listA
               from b in a.ListB
               select new KeyValuePair&lt;T1,List&lt;T2&gt;&gt;{ T1=a , T2=b})
  </code></pre>
  
  <p>The first query produces a list of items like this: {(a,x), (a,y), (a,z), (b,x) ...}</p>
  
  <p>The intent of the second query is to merge the results into items with their own lists. </p>
  
  <p>Results would look like this: </p>
  
  <p>{(a,List with items x,y,z), (b, List with item x) ...}</p>
  
  <p>I'd appreciate the help. Thanks!</p>