Find the depth level in parent-child hierarchy
<p>I've the table structure like below.</p>

<pre><code>Id  |ParentId|  Name
--- |--------|-------
1   |NULL    |A
2   |1       |B
3   |2       |C
4   |3       |D
</code></pre>

<p>A is parent of B, B is parent of C and C is parent of D.</p>

<p>I want to calculate how may parents each record have?
For example B is referring A, C is referring B and D is referring C.</p>

<p>In this case depth level for A is 0, B is 1, C is 2 and D is 3, based on number of parents they have.</p>

<p>I can do this using recursive function, querying each time if the record has any parent. I want to achieve this using linq query in an efficient way. </p>