Parsing Hierarchical self-join table by tree level?

I suggest you use a recursive Common Table Expression using the with keyword. Have a look at this article on MSDN and my own question here.

You can't do this easily in a single LINQ query. You should use recursion. Either write a recursive function in C# or use a recursive CTE in the database.

For the C# solution: IEnumerable> GetChildren(int id, int childLevel) { foreach (var row in rows. Where(row => row. ParentID == id && row.ID!

= id)) { yield return new KeyValuePair(row. ID, childLevel); foreach (var x in GetChildren(row.ID, childLevel + 1)) { yield return x; } } } Call as follows: GetChildren(0, 0).

It is better to do it with C# code for me! – mahdiahmadirad Oct 29 '10 at 19:47.

I agree with the previous answers; you can't do a magical query that will give you the tree level. Erarchies like this are often better served with a nested set structure rather than a parent pointer: en.wikipedia.org/wiki/Nested_set_model This article shows you some common queries for working with nested set data: dev.mysql.com/tech-resources/articles/hi....

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions