given the following class …
public class Category { public string Name {get;set;} public Category ParentCategory {get;set;} }
What the most efficient way to output the following from a collection (IList<Category>) of Category objects?
+ Parent Category ++ Sub Category ++ Sub Category 2 + Parent Category 2 ++ Sub ... ++ Sub .. ++ Sub ....
EDIT: Perhaps the real question should be, how should I represent this model in the database and retrieve it using NHibernate?
You may wish to consider reversing your relationship. If a node can get to its parent but not vice versa, you have to have all the leaf nodes in order to print out the full tree. Compare this to the situation where you have each node know about its children – then you only need the root node.