private string GetInheritedNamespace(List<DataTable> visitedTables)
{
// if there is nested relation: ie: this table is nested child of a another table and
// if it is not self nested, return parent tables NS: Meanwhile make sure
DataRelation[] nestedRelations = NestedParentRelations;
if (nestedRelations.Length > 0)
{
for (int i = 0; i < nestedRelations.Length; i++)
{
DataRelation rel = nestedRelations[i];
if (rel.ParentTable._tableNamespace != null)
{
return rel.ParentTable._tableNamespace; // if parent table has a non-null NS, return it
}
}
// Assumption, in hierarchy of multiple nested relation, a child table with no NS, has DataRelation
// only and only with parent DataTable witin the same namespace
int j = 0;
while (j < nestedRelations.Length && ((nestedRelations[j].ParentTable == this) || (visitedTables.Contains(nestedRelations[j].ParentTable))))
{
j++;
}
if (j < nestedRelations.Length)
{
DataTable parentTable = nestedRelations[j].ParentTable;
if (!visitedTables.Contains(parentTable))
visitedTables.Add(parentTable);
return parentTable.GetInheritedNamespace(visitedTables);// this is the same as return parentTable.Namespace
}
} // dont put else
if (DataSet != null)
{
// if it cant return from parent tables, return NS from dataset, if exists
return DataSet.Namespace;
}
else
{
return string.Empty;
}
}