Search code examples
linqsubsonic

Subsonic 3 and The Adjacency Model


If a table has the adjacency model applied (ID,ParentID) how can the hierarchy be returned in Subsonic 3?


Solution

  • All classes are partials, so create a new partial for your class (let's say it' Category) and create child collection (call it SubCategories). Then when you load your object into memory you can load the subcollection:

    var allCategories=Categories.All().ToList();
    allCategories.ForEach(x=>x.SubCategories=allCategories.Where(y=>y.CategoryID==x.ParentID));
    

    That's freehanded, but that's the idea.