Exemplo n.º 1
0
        // IDataAdapter.MissingSchemaAction
        internal static ArgumentOutOfRangeException InvalidMissingSchemaAction(MissingSchemaAction value)
        {
#if DEBUG
            switch (value)
            {
            case MissingSchemaAction.Add:
            case MissingSchemaAction.Ignore:
            case MissingSchemaAction.Error:
            case MissingSchemaAction.AddWithKey:
                Debug.Assert(false, "valid MissingSchemaAction " + value.ToString());
                break;
            }
#endif
            return(InvalidEnumerationValue(typeof(MissingSchemaAction), (int)value));
        }
Exemplo n.º 2
0
        private void MergeRelation(DataRelation relation)
        {
            Debug.Assert(_dataSet != null);
            Debug.Assert(MissingSchemaAction.Error == _missingSchemaAction ||
                         MissingSchemaAction.Add == _missingSchemaAction,
                         "Unexpected value of MissingSchemaAction parameter : " + _missingSchemaAction.ToString());
            DataRelation?destRelation = null;

            // try to find given relation in this dataSet

            int iDest = _dataSet.Relations.InternalIndexOf(relation.RelationName);

            if (iDest >= 0)
            {
                // check the columns and Relation properties..
                destRelation = _dataSet.Relations[iDest];

                if (relation.ParentKey.ColumnsReference.Length != destRelation.ParentKey.ColumnsReference.Length)
                {
                    _dataSet.RaiseMergeFailed(null,
                                              SR.Format(SR.DataMerge_MissingDefinition, relation.RelationName),
                                              _missingSchemaAction);
                }
                for (int i = 0; i < relation.ParentKey.ColumnsReference.Length; i++)
                {
                    DataColumn dest = destRelation.ParentKey.ColumnsReference[i];
                    DataColumn src  = relation.ParentKey.ColumnsReference[i];

                    if (0 != string.Compare(dest.ColumnName, src.ColumnName, false, dest.Table !.Locale))
                    {
                        _dataSet.RaiseMergeFailed(null,
                                                  SR.Format(SR.DataMerge_ReltionKeyColumnsMismatch, relation.RelationName),
                                                  _missingSchemaAction);
                    }

                    dest = destRelation.ChildKey.ColumnsReference[i];
                    src  = relation.ChildKey.ColumnsReference[i];

                    if (0 != string.Compare(dest.ColumnName, src.ColumnName, false, dest.Table !.Locale))
                    {
                        _dataSet.RaiseMergeFailed(null,
                                                  SR.Format(SR.DataMerge_ReltionKeyColumnsMismatch, relation.RelationName),
                                                  _missingSchemaAction);
                    }
                }
            }
            else
            {
                if (MissingSchemaAction.Add == _missingSchemaAction)
                {
                    // create identical realtion in the current dataset
                    DataTable parent = _IgnoreNSforTableLookup ?
                                       _dataSet.Tables[relation.ParentTable.TableName] ! :
                                       _dataSet.Tables[relation.ParentTable.TableName, relation.ParentTable.Namespace] !;

                    DataTable child = _IgnoreNSforTableLookup ?
                                      _dataSet.Tables[relation.ChildTable.TableName] ! :
                                      _dataSet.Tables[relation.ChildTable.TableName, relation.ChildTable.Namespace] !;

                    DataColumn[] parentColumns = new DataColumn[relation.ParentKey.ColumnsReference.Length];
                    DataColumn[] childColumns  = new DataColumn[relation.ParentKey.ColumnsReference.Length];
                    for (int i = 0; i < relation.ParentKey.ColumnsReference.Length; i++)
                    {
                        parentColumns[i] = parent.Columns[relation.ParentKey.ColumnsReference[i].ColumnName] !;
                        childColumns[i]  = child.Columns[relation.ChildKey.ColumnsReference[i].ColumnName] !;
                    }
                    try
                    {
                        destRelation        = new DataRelation(relation.RelationName, parentColumns, childColumns, relation._createConstraints);
                        destRelation.Nested = relation.Nested;
                        _dataSet.Relations.Add(destRelation);
                    }
                    catch (Exception e) when(Common.ADP.IsCatchableExceptionType(e))
                    {
                        ExceptionBuilder.TraceExceptionForCapture(e);
                        _dataSet.RaiseMergeFailed(null, e.Message, _missingSchemaAction);
                        // TODO: destRelation may be null, causing an NRE below
                    }
                }
                else
                {
                    Debug.Assert(MissingSchemaAction.Error == _missingSchemaAction, "Unexpected value of MissingSchemaAction parameter : " + _missingSchemaAction.ToString());
                    throw ExceptionBuilder.MergeMissingDefinition(relation.RelationName);
                }
            }

            // TODO: destRelation may be null, see comment above
            MergeExtendedProperties(relation.ExtendedProperties, destRelation !.ExtendedProperties);
        }