internal void AddAt(int index, DataColumn column) { if (column != null && column.ColumnMapping == MappingType.SimpleContent) { if (_table.XmlText != null && _table.XmlText != column) { throw ExceptionBuilder.CannotAddColumn3(); } if (_table.ElementColumnCount > 0) { throw ExceptionBuilder.CannotAddColumn4(column.ColumnName); } OnCollectionChanging(new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); BaseAdd(column); if (index != -1) { ArrayAdd(index, column); } else { ArrayAdd(column); } _table.XmlText = column; } else { OnCollectionChanging(new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); BaseAdd(column); if (index != -1) { ArrayAdd(index, column); } else { ArrayAdd(column); } // if the column is an element increase the internal dataTable counter if (column.ColumnMapping == MappingType.Element) { _table.ElementColumnCount++; } } if (!_table.fInitInProgress && column != null && column.Computed) { column.CopyExpressionFrom(column); } OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, column)); }
internal void MergeDataSet(DataSet source) { Debug.Assert(_dataSet != null); if (source == _dataSet) { return; //somebody is doing an 'automerge' } bool fEnforce = _dataSet.EnforceConstraints; _dataSet.EnforceConstraints = false; _IgnoreNSforTableLookup = (_dataSet._namespaceURI != source._namespaceURI); // if two DataSets have different // Namespaces, ignore NS for table lookups as we won't be able to find the right tables which inherits its NS List <DataColumn>?existingColumns = null; // need to cache existing columns if (MissingSchemaAction.Add == _missingSchemaAction) { existingColumns = new List <DataColumn>(); // need to cache existing columns foreach (DataTable dt in _dataSet.Tables) { foreach (DataColumn dc in dt.Columns) { existingColumns.Add(dc); } } } for (int i = 0; i < source.Tables.Count; i++) { MergeTableData(source.Tables[i]); // since column expression might have dependency on relation, we do not set //column expression at this point. We need to set it after adding relations } if (MissingSchemaAction.Ignore != _missingSchemaAction) { // Add all independent constraints MergeConstraints(source); // Add all relationships for (int i = 0; i < source.Relations.Count; i++) { MergeRelation(source.Relations[i]); } } if (MissingSchemaAction.Add == _missingSchemaAction) { // for which other options we should add expressions also? foreach (DataTable sourceTable in source.Tables) { DataTable targetTable; if (_IgnoreNSforTableLookup) { targetTable = _dataSet.Tables[sourceTable.TableName] !; } else { targetTable = _dataSet.Tables[sourceTable.TableName, sourceTable.Namespace] !; // we know that target table won't be null since MissingSchemaAction is Add , we have already added it! } foreach (DataColumn dc in sourceTable.Columns) { // Should we overwrite the previous expression column? No, refer to spec, if it is new column we need to add the schema if (dc.Computed) { DataColumn targetColumn = targetTable.Columns[dc.ColumnName] !; if (!existingColumns !.Contains(targetColumn)) { targetColumn.CopyExpressionFrom(dc); } } } } } MergeExtendedProperties(source.ExtendedProperties, _dataSet.ExtendedProperties); foreach (DataTable dt in _dataSet.Tables) { dt.EvaluateExpressions(); } _dataSet.EnforceConstraints = fEnforce; }