ASP.NET Eager-loading a tree hierarchy of references
<p>With my current database model I'm trying to load the complete table set with every reference and sub-references an entry may have. That is so the view can display the query in a tree like hierarchy. Where each entry lies under its parent.</p>

<p>Say in the following fashion</p>

<ul>
<li>Real Estate

<ul>
<li>Apartment</li>
</ul></li>
<li>Vehicle

<ul>
<li>Land

<ul>
<li>Urban</li>
<li>Terrain</li>
</ul></li>
<li>Air </li>
<li>Water</li>
</ul></li>
</ul>

<p>The problem stems from that the entries have to be loaded with there parents and parents parents .etc depending on the depth of the tree. I suspect that it have to do with that an entry may have cyclic references.</p>

<p>Can this be achieved with my current db model or do I need to change it?</p>

<pre><code>using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace MySolution.Models
{
    public class Category
    {
       [Key]
       public string Name { get; set; }

       public string ImageSource { get; set; }

       public Category Parent { get; set;  }


       public virtual ICollection&lt;Category&gt; Children { get; set; }
   }
}
</code></pre>

<p>Thanks</p>