I wanted to select all related records from a self referencing table using entity framework . I don't have any specific level . It's just for all related records all child and all parent . Below is some sample data . So If I pass ID 5 to my function it should give me records having id 1,4,5,7,8 .
5 is the parent id for Id 7 and 7 is the parent id for Id 8 . Similarly parent id for 5 is 1 and 1 is also the parent id for Id 4 .
So in this way I would like to select all beneath and above records of Id 5 .
Data Source
Id Name ParentId
1 Test 1 NULL
2 Test 2 NULL
3 Test 3 NULL
4 Test 4 1
5 Test 5 1
6 Test 6 4
7 Test 7 5
8 Test 7 7
Expected
1 Test 1 NULL
4 Test 4 1
5 Test 5 1
7 Test 7 5
8 Test 7 7