I have a database table with customers:
Table:
[Customer]
Fields:
[Id] Integer
[ParentId] Integer
Customers have, among other things, a unique Id and a ParentId that point to the customer that created it. So, every customer can have sub customers, whom can have sub customers etc.
Etc:
Customer{ Id = 1, ParentId = 1 } //Root customer
Customer{ Id = 123, ParentId = 1}
Customer{ Id = 456, ParentId = 1}
Customer{ Id = 789, ParentId = 1}
Customer{ Id = 321, ParentId = 123 }
Customer{ Id = 654, ParentId = 123 }
Customer{ Id = 987, ParentId = 789 }
Customer{ Id = 1010, ParentId = 987 }
I use EF and LINQ to query my data.
What I need, is a LINQ query to get all Id's flattened, based in an Id.
E.g.:
Id 1 will return all Id's.
Id 123 will return 321 and 654
Id 789 will return 987 and 1010