private DataTable CloneHierarchy (DataTable sourceTable, DataSet ds, Hashtable visitedMap) { if (visitedMap == null) visitedMap = new Hashtable(); if (visitedMap.Contains(sourceTable)) return ((DataTable)visitedMap[sourceTable]); DataTable destinationTable = ds.Tables[sourceTable.TableName, sourceTable.Namespace]; if ((destinationTable != null && destinationTable.Columns.Count > 0)) { destinationTable = IncrementalCloneTo(sourceTable,destinationTable); // get extra columns from source into destination , increamental read } else { if (destinationTable == null) { destinationTable = new DataTable(); // fxcop: new DataTable values for CaseSensitive, Locale, Namespace will come from CloneTo ds.Tables.Add(destinationTable); } destinationTable = sourceTable.CloneTo(destinationTable, ds, true); } visitedMap[sourceTable] = destinationTable; // start cloning relation foreach( DataRelation r in sourceTable.ChildRelations ) { DataTable childTable = CloneHierarchy((DataTable)r.ChildTable, ds, visitedMap); } return destinationTable; }
private DataTable CloneHierarchy(DataTable sourceTable, System.Data.DataSet ds, Hashtable visitedMap) { if (visitedMap == null) { visitedMap = new Hashtable(); } if (visitedMap.Contains(sourceTable)) { return (DataTable) visitedMap[sourceTable]; } DataTable targetTable = ds.Tables[sourceTable.TableName, sourceTable.Namespace]; if ((targetTable != null) && (targetTable.Columns.Count > 0)) { targetTable = this.IncrementalCloneTo(sourceTable, targetTable); } else { if (targetTable == null) { targetTable = new DataTable(); ds.Tables.Add(targetTable); } targetTable = sourceTable.CloneTo(targetTable, ds, true); } visitedMap[sourceTable] = targetTable; foreach (DataRelation relation in sourceTable.ChildRelations) { this.CloneHierarchy(relation.ChildTable, ds, visitedMap); } return targetTable; }