private void BuildIdentityMap(XmlNameTable nameTable, DataSet dataSet)
{
_tableSchemaMap = new XmlNodeIdHashtable(dataSet.Tables.Count);
// This hash table contains
// tables schemas as TableSchemaInfo objects
// These objects holds reference to the table.
// Hash tables with columns schema maps
// and child tables schema maps
string dsNamespace = nameTable.Get(dataSet.Namespace); // Attept to look up DataSet namespace
// in the name table
if (dsNamespace == null)
{ // Found ?
dsNamespace = nameTable.Add(dataSet.Namespace); // Nope. Add it
}
dataSet._namespaceURI = dsNamespace; // Set a DataSet namespace URI
foreach (DataTable t in dataSet.Tables)
{ // For each table
TableSchemaInfo tableSchemaInfo = AddTableSchema(nameTable, t);
// Add table schema info to hash table
if (tableSchemaInfo != null)
{
foreach (DataColumn c in t.Columns)
{ // Add column schema map
// don't include auto-generated PK, FK and any hidden columns to be part of mapping
if (IsMappedColumn(c))
{ // If mapped column
AddColumnSchema(nameTable, c, tableSchemaInfo.ColumnsSchemaMap);
} // Add it to the map
}
// Add child nested tables to the schema
foreach (DataRelation r in t.ChildRelations)
{ // Do we have a child tables ?
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;
}
}
}
}
}