title: How to search Hierarchical Data with Linq
body: <p>I need to search a tree for data that could be anywhere in the tree.  How can this be done with linq?</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args) {
  
          var familyRoot = new Family() {Name = "FamilyRoot"};
  
          var familyB = new Family() {Name = "FamilyB"};
          familyRoot.Children.Add(familyB);
  
          var familyC = new Family() {Name = "FamilyC"};
          familyB.Children.Add(familyC);
  
          var familyD = new Family() {Name = "FamilyD"};
          familyC.Children.Add(familyD);
  
          //There can be from 1 to n levels of families.
          //Search all children, grandchildren, great grandchildren etc, for "FamilyD" and return the object.
  
  
      }
  }
  
  public class Family {
      public string Name { get; set; }
      List&lt;Family&gt; _children = new List&lt;Family&gt;();
  
      public List&lt;Family&gt; Children {
          get { return _children; }
      }
  }
  </code></pre>