I have a recursive method that is return me categories, and checking for its sub categories.
So it looks like:
public List GetAllChildCat
Here's a modified version of Jon Skeet's answer using a local method (C# 7) :
public List GetAllChildCats(int rootId)
{
List list = new List();
Traverse(rootId);
return list;
void Traverse(int categoryId)
{
Category c = Get(categoryId);
list.Add(c);
foreach (Category cat in c.ChildCategories)
{
Traverse(cat.CategoryID);
}
}
}