Walking a hierarchy table with Linq
        Posted  
        
            by Retrocoder
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Retrocoder
        
        
        
        Published on 2010-04-01T12:36:37Z
        Indexed on 
            2010/04/01
            14:13 UTC
        
        
        Read the original article
        Hit count: 324
        
c#
|linq-to-entities
I have a table with two columns, GroupId and ParentId (both are GUIDS). The table forms a hierarchy so I can look for a value in the “GroupId” filed, when I have found it I can look at its ParentId. This ParentId will also appear in the GroupId of a different record. I can use this to walk up the hierarchy tree from any point to the root (root is an empty GUID). What I’d like to do is get a list of records when I know a GroupId. This would be the record with the GroupId and all the parents back to the root record. Is this possible with Linq and if so, can anyone provide a code snippet?
© Stack Overflow or respective owner