Building Ordering a tree as a list in C#
<p>I have a list of C# entities. My entity is defined as follows:</p>

<pre><code>public class Item
{
    // the id of an item
    public Guid ID { get; set; }

    // if this is a child item, the ParentID is the ID of the item that
    // this item is a child of
    public Guid? ParentID { get; set; }

    // If this item does not have a parent, this should be 0.
    // Otherwise if it is a child, a level=1
    // If it is a grandchild, level=2, etc.
    public int Level { get; set; }

    // The UTC date the item was created on.
    public DateTime CreateDate { get; set; }
}
</code></pre>

<p>My list of these entities is in a random order. I'm trying to figure out how to sort my list of entities such that the item elements are sorted by level (ascending) and then createDate (ascending). Essentially a list would look like this:</p>

<pre><code>Item 1 (Level 0)
  Item 2 (Level 1)
    Item 3 (Level 2)
    Item 4 (Level 2)
  Item 5 (Level 1)
Item 6 (Level 0)
  Item 7 (Level 2)
etc.
</code></pre>

<p>This seems easy enough. Maybe I've been looking at it too long. But I can seem to get it to work. Any ideas? </p>
