title: Get Parents for Entity in Hierarchy
body: <p>Been trying to solve this without progress for a couple days, my question:</p>
  
  <blockquote>
    <p>Given an entity in a hierarchy, return
    a list of the immediate-ascendants (or
    parent<b>s</b>) of the entity.</p>
  </blockquote>
  
  <p>When I want to know the hierarchy of "Entity 1.2.2.2" it would return a list containing only the bold items:</p>
  
  <pre>
  <b>Entity 1</b>
  - Entity 1.1
  - <b>Entity 1.2</b>
    - Entity 1.2.1
    - <b>Entity 1.2.2</b>
      - Entity 1.2.2.1
      - <b>Entity 1.2.2.2</b>
    - Entity 1.2.3
    - Entity 1.2.4
      - Entity 1.2.4.1
  - Entity 1.3
  - Entity 1.4
  Entity 2
  ...
  </pre>
  
  <p>Hence, expected result:</p>
  
  <pre>
  <b>Entity 1</b>
  - <b>Entity 1.2</b>
    - <b>Entity 1.2.2</b>
      - <b>Entity 1.2.2.2</b>
  </pre>
  
  <p>Implementation code:</p>
  
  <pre><code>class Entity
  {
      public Entity Parent { get; set; }
  
      public bool AbsoluteParent 
      { 
          get
          { 
              return Parent == null;
          } 
      }
  
      public IEnumerable&lt;Entity&gt; Hierarchy //problem
      { 
          get
          {
              return AbsoluteParent 
                  ? new [] { this }
                  : new [] { this }.Concat( Parent.Hierarchy );
          }
      }
  
  }
  </code></pre>
  
  <p>The array attempt above is just one of the options I have been trying, that code actually returns something like:</p>
  
  <pre>
  <b>Entity 1</b>
  <b>Entity 1</b>
  - <b>Entity 1.2</b>
  <b>Entity 1</b>
  - <b>Entity 1.2</b>
    - <b>Entity 1.2.2</b>
  <b>Entity 1</b>
  - <b>Entity 1.2</b>
    - <b>Entity 1.2.2</b>
      - <b>Entity 1.2.2.2</b>
  </pre>
  
  <p>I am able to achieve the expected results using jQuery's <code>parents()</code> function, I've been reading the <code>yield return</code> keywords but still stuck in its more (I guess) functional style which I'm still baby-stepping into.</p>