I have Category table that has a relation on itself. That is it's a tree hierarchical view, for example: oldfather_category -> father_category -> child_category.
So I need to build tree view on this table. I need the all rows from it. At first i do this:
IEnumerable<Category> list = _service.Get().Where(c => c.ParentID == null);
Node(list);
When I use the recurcive like this:
private void Node(IEnumerable<Category> list)
{
foreach (Category c in list)
{
//if has childs
if (c.Category1.Count > 0)
Node(c.Category1);
}
}
entity framework builds select every time when I call c.Category1.Count property (Deferred Execution magic). But I want to load the all entities in first statement, I want make the only select to sql server. How can I do that? I hope the question is clear)
Edited: when I use ToList() the Category1 property is null whatever