LINQ AsHierarchy() improvements

A few months ago I published an article about my LINQ AsHierarchy extension method. This extension method can be used to convert a flat collection of records to a hierarchical structure of nested collections.

I got a lot of enthusiastic responses and questions and so I decided to improve this technique a little further. So I added a Parent reference in the HierarchyNode object and the AsHierarchy() method has been extended with RootID and MaxDepth parameters.

I also wrote a new article which describes these new features and demonstrates how to use the LINQ to Objects and the new LINQ to SQL AsHierarchy extension methods. Check it out at my personal website:


Tags: , , , ,

One response to “LINQ AsHierarchy() improvements”

  1. Krishna says :

    Hi Stefan Cruysberghs

    Thank you very much for the AsHierarchy() Linq Extension. This is very useful and I greatly appreciate it.

    I am wondering whether you will have some time to think guide me in writing the reverse of your extension.

    Meaning what you have provided is a down-chain hierarchy (given root, get the children and grand childeren), I will be needing a up-chain hierarchy (given child, get all the parents and grand parents).

    Any thoughts on this will be greatly honored.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: