我有一个sql数据库并输入任何表名,我是cretae table hiyerarchy,如下所示。
Z A B C D E F是表名,Z in是外国ID。 A中有B外国身份证。但是当F表中有D或Z ID名称时。这种递归方法不会停止。
我如何检测到表格中的儿童。
Z
A
B
C=> The continuation of here if comes Z or A or B ID Method not stop and call itself.
D
E
F=> The continuation of here if comes D or Z ID Method not stop and call itself.
D
Z
答案 0 :(得分:0)
以上是上述评论中提出的方法示例...
void RecursiveMethod( Table table, List<string> visitedTables )
{
// note the currently visited table
var extendedList = visitedTables.ToList();
extendedList.Add( table.Name );
// do your thing with the table...
// ... and recurse deeper
foreach (var referencedTable in table.ReferencedTables)
if (!visitedTables.Contains( referencedTable.Name ))
RecursiveMethod( referencedTable, extendedList );
}
然后从
开始RecursiveMethod( theRootTable, new List<string>() );