我有来自数据库的数据:
id | description | parent_id
-----------------------------------------
1 | Record 1 | null
2 | Record 2 | 1
3 | Record 3 | null
4 | Record 4 | 2
5 | Record 5 | 3
Run Code Online (Sandbox Code Playgroud)
我想使用Linq进行处理,它应该是这样的结果:
Record 1
- Record 2
- Record 4
Record 3
- Record 5
Run Code Online (Sandbox Code Playgroud)
我得到了解决方案:递归LINQ查询:选择项目和所有子女孩子
但不幸的是结果只有两个级别,因为我希望结果处于多级> 2级(如树).
还有其他最佳方法吗?或者如何修改该解决方案
提前致谢
我有一个表,包含下面显示的数据,它叫做TABLE_A
+++++++++++++++++++++++++++++++++++++++++++++ PrimaryID | Col2 | SecondaryID +++++++++++++++++++++++++++++++++++++++++++++ 1 | Description 1 | 0 2 | Description 2 | 0 3 | Description 3 | 0 4 | Description 4 | 0 . | ... | . . | .
请参阅上面的SecondaryID.它的零值作为初始值
我有另一张桌子,下面叫做TABLE_B
+++++++++++++++++++++++++++++++++++++++++++++ PrimaryID | Col2 | ForeignKeyID +++++++++++++++++++++++++++++++++++++++++++++ 1 | Description 1 | 123 2 | Description 2 | 320 3 | Description 3 | 111 4 | Description 4 | 999 . | ... | . …