title: Remove parents from list
body: <p>I have 2 lists, both containing objects which look like this: (this is a simplification)</p>
  
  <pre><code>class ddItem
  {
      public string Code;
      public string Key;
      public string ParentKey;
  }
  </code></pre>
  
  <p>One list contains items which may or may not have children in the other list.
  I'm trying to figure out a nice way to remove items from the parent list if they have a corresponding item in the child list, i.e. where parent.Key = child.parentKey.</p>
  
  <p>This is the LINQ I have, and it's currently causing me to lose brain cells:</p>
  
  <pre><code>parentList = 
      (List&lt;ddItem&gt;)parentList.Where(p =&gt; childList.Select(c =&gt; c.ParentKey == p.Key));
  </code></pre>
  
  <p>Currently I have a red squiggly line under <code>childList.Select(c =&gt; c.ParentKey == p.Key)</code> and the message <code>Cannot convert expression type 'System.Collections.Generic.IEnumerable&lt;bool&gt;' to return type 'bool'</code> so I must be missing a cast somewhere - I think...</p>
  
  <p>[EDIT]</p>
  
  <p>For posterity, the correct code is:</p>
  
  <pre><code>parentList = 
      parentList.Where(p =&gt; childList.Any(c =&gt; c.ParentKey == p.Key)).ToList();
  </code></pre>
  
  <p>(I also had to move the cast)</p>
  
  <p>[/EDIT]</p>