0

Assume my structure of data would be like the below,

enter image description here

If I give ExtensionId = 2, should traverse through Id(parent) like 2 -> 3 -> 4 until the ExtensionId becomes null?

Need the above requirement in linq not stored procedure.

Vasundhara
  • 13
  • 4
  • **TL;DR:**: You can't. Linq is an implementation of Relational Algebra (whereas SQL is a (piss-poor) example of Relational Calculus). Excepting extensions such as self-referential CTEs in SQL, neither system is suitable for expressing and evaluating recursive and graph-traversal queries (hence [Colby's 1990 paper](https://www.sciencedirect.com/science/article/abs/pii/030643799090029O)). So if you want to do this efficiently you **need** to use a recursive CTE in raw SQL, and if you have a "requirement" to do it in Linq then tell your boss/client to go pound sand. – Dai Sep 23 '22 at 13:45

0 Answers0