Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Recursive Efficiency!

$
0
0

Hi all,

I'm trying to speed up a hierarchical tree builder with LINQ, this is what I have but it takes ages for trees that are thousands deep! Any tip on speeding this up at all?

void TreeBuilder(IEnumerable<Tree> data, int? id = null)
            {
                var items = data.Where(d => d.parentId == id).OrderBy(o => o.id);
                if (items.Any())
                {
                    foreach (var item in items)
                    {
                        teamList.Add(Tuple.Create(item.id, Convert.ToInt32(item.parentId)));
                        TreeBuilder(data, item.id);
                    }
                }
            }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>