private void BuildIdentityMap(XmlNameTable nameTable, DataTable dataTable)
{
ArrayList tableList = GetSelfAndDescendants(dataTable); // Get list of tables we're loading
// This includes our table and
// related tables tree
_tableSchemaMap = new XmlNodeIdHashtable(tableList.Count);
// Create hash table to hold all
// tables to load.
foreach (DataTable t in tableList)
{ // For each table
TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t);
// Create schema info
if (tableSchemaInfo != null)
{
foreach (DataColumn c in t.Columns)
{ // Add column information
// don't include auto-generated PK, FK and any hidden columns to be part of mapping
if (IsMappedColumn(c))
{
AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap);
}
}
foreach (DataRelation r in t.ChildRelations)
{ // Add nested tables information
if (r.Nested)
{ // Is it nested?
// don't include non nested tables
// Handle namespaces and names as usuall
string _tableLocalName = XmlConvert.EncodeLocalName(r.ChildTable.TableName);
string tableLocalName = nameTable.Get(_tableLocalName);
if (tableLocalName == null)
{
tableLocalName = nameTable.Add(_tableLocalName);
}
string tableNamespace = nameTable.Get(r.ChildTable.Namespace);
if (tableNamespace == null)
{
tableNamespace = nameTable.Add(r.ChildTable.Namespace);
}
XmlNodeIdentety idTable = new XmlNodeIdentety(tableLocalName, tableNamespace);
tableSchemaInfo.ColumnsSchemaMap[idTable] = r.ChildTable;
}
}
}
}
}