Get Hierarchical Data Using Linq2Sql
-
What is the best way to retrieve hierarchical data using Linq2Sql? I have a tree of data and i want to pull it out and put it in my own classes. The data is for a menu and I have a menu class which has children which are menu items these children in turn have children etc... I want to pull the whole tree and place it into my own classes. The most logical way i could think of doing this was to have an extension method that can recursively convert EntitySet to List i would then call this from m in DataContext.Menus where m.ID == ID select new Menu(){ Name = m.Name, ID = m.ID, Childen = m.LinqMenuItems.ToChildren()}; The ToChildren would then recursively convert all LinqMenuItems and their Children LinqMenuItems to my MenuItem implementation. The problem with this approach is that I get an error saying ToChildren doesn't have a translation to SQL. Seemingly I cant use my own extension methods in a Linq2Sql query. Any Ideas?