/// <summary> /// Does verification on the table. /// An ArgumentNullException is thrown if this relation is null. An ArgumentException is thrown if this relation /// already belongs to this collection, belongs to another collection. /// A DuplicateNameException is thrown if this collection already has a relation with the same /// name (case insensitive). /// </summary> protected virtual void AddCore(DataRelation relation) { DataCommonEventSource.Log.Trace("<ds.DataRelationCollection.AddCore|INFO> {0}, relation={1}", ObjectID, (relation != null) ? relation.ObjectID : 0); if (relation == null) { throw ExceptionBuilder.ArgumentNull(nameof(relation)); } relation.CheckState(); DataSet dataSet = GetDataSet(); if (relation.DataSet == dataSet) { throw ExceptionBuilder.RelationAlreadyInTheDataSet(); } if (relation.DataSet != null) { throw ExceptionBuilder.RelationAlreadyInOtherDataSet(); } if (relation.ChildTable.Locale.LCID != relation.ParentTable.Locale.LCID || relation.ChildTable.CaseSensitive != relation.ParentTable.CaseSensitive) { throw ExceptionBuilder.CaseLocaleMismatch(); } if (relation.Nested) { relation.CheckNamespaceValidityForNestedRelations(relation.ParentTable.Namespace); relation.ValidateMultipleNestedRelations(); relation.ParentTable.ElementColumnCount++; } }
protected virtual void AddCore(DataRelation relation) { Bid.Trace("<ds.DataRelationCollection.AddCore|INFO> %d#, relation=%d\n", this.ObjectID, (relation != null) ? relation.ObjectID : 0); if (relation == null) { throw ExceptionBuilder.ArgumentNull("relation"); } relation.CheckState(); DataSet dataSet = this.GetDataSet(); if (relation.DataSet == dataSet) { throw ExceptionBuilder.RelationAlreadyInTheDataSet(); } if (relation.DataSet != null) { throw ExceptionBuilder.RelationAlreadyInOtherDataSet(); } if ((relation.ChildTable.Locale.LCID != relation.ParentTable.Locale.LCID) || (relation.ChildTable.CaseSensitive != relation.ParentTable.CaseSensitive)) { throw ExceptionBuilder.CaseLocaleMismatch(); } if (relation.Nested) { relation.CheckNamespaceValidityForNestedRelations(relation.ParentTable.Namespace); relation.ValidateMultipleNestedRelations(); DataTable parentTable = relation.ParentTable; parentTable.ElementColumnCount++; } }
/// <include file='doc\DataRelationCollection.uex' path='docs/doc[@for="DataRelationCollection.AddCore"]/*' /> /// <devdoc> /// Does verification on the table. /// An ArgumentNullException is thrown if this relation is null. An ArgumentException is thrown if this relation /// already belongs to this collection, belongs to another collection. /// A DuplicateNameException is thrown if this collection already has a relation with the same /// name (case insensitive). /// </devdoc> protected virtual void AddCore(DataRelation relation) { if (relation == null) { throw ExceptionBuilder.ArgumentNull("relation"); } relation.CheckState(); DataSet dataSet = GetDataSet(); if (relation.DataSet == dataSet) { throw ExceptionBuilder.RelationAlreadyInTheDataSet(); } if (relation.DataSet != null) { throw ExceptionBuilder.RelationAlreadyInOtherDataSet(); } if (relation.ChildTable.Locale.LCID != relation.ParentTable.Locale.LCID || relation.ChildTable.CaseSensitive != relation.ParentTable.CaseSensitive) { throw ExceptionBuilder.CaseLocaleMismatch(); } if (relation.Nested) { relation.ParentTable.ElementColumnCount++; } }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if (relation.ChildTable.DataSet != dataSet || relation.ParentTable.DataSet != dataSet) throw ExceptionBuilder.ForeignRelation(); relation.CheckState(); if(relation.Nested) { relation.CheckNestedRelations(); } if (relation.relationName.Length == 0) relation.relationName = AssignName(); else RegisterName(relation.relationName); DataKey childKey = relation.ChildKey; for (int i = 0; i < relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)relations[i]).ChildKey)) { if (relation.ParentKey.ColumnsEqual(((DataRelation)relations[i]).ParentKey)) throw ExceptionBuilder.RelationAlreadyExists(); } } relations.Add(relation); ((DataRelationCollection.DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Add(relation); // Caching in ParentTable -> ChildRelations ((DataRelationCollection.DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Add(relation); // Caching in ChildTable -> ParentRelations relation.SetDataSet(dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint foreignKey = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation.createConstraints) { if (foreignKey == null) { relation.ChildTable.Constraints.Add(foreignKey = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); // try to name the fk constraint the same as the parent relation: try { foreignKey.ConstraintName = relation.RelationName; } catch (Exception e) { // if (!Common.ADP.IsCatchableExceptionType(e)) { throw; } ExceptionBuilder.TraceExceptionWithoutRethrow(e); // ignore the exception } } } UniqueConstraint key = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(key); relation.SetChildKeyConstraint(foreignKey); }
/// <devdoc> /// Does verification on the table. /// An ArgumentNullException is thrown if this relation is null. An ArgumentException is thrown if this relation /// already belongs to this collection, belongs to another collection. /// A DuplicateNameException is thrown if this collection already has a relation with the same /// name (case insensitive). /// </devdoc> protected virtual void AddCore(DataRelation relation) { Bid.Trace("<ds.DataRelationCollection.AddCore|INFO> %d#, relation=%d\n", ObjectID, (relation != null) ? relation.ObjectID : 0); if (relation == null) throw ExceptionBuilder.ArgumentNull("relation"); relation.CheckState(); DataSet dataSet = GetDataSet(); if (relation.DataSet == dataSet) throw ExceptionBuilder.RelationAlreadyInTheDataSet(); if (relation.DataSet != null) throw ExceptionBuilder.RelationAlreadyInOtherDataSet(); if (relation.ChildTable.Locale.LCID != relation.ParentTable.Locale.LCID || relation.ChildTable.CaseSensitive != relation.ParentTable.CaseSensitive) throw ExceptionBuilder.CaseLocaleMismatch(); if (relation.Nested) { relation.CheckNamespaceValidityForNestedRelations(relation.ParentTable.Namespace); relation.ValidateMultipleNestedRelations(); relation.ParentTable.ElementColumnCount++; } }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if (relation.ChildTable.DataSet != _dataSet || relation.ParentTable.DataSet != _dataSet) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation._relationName.Length == 0) { relation._relationName = AssignName(); } else { RegisterName(relation._relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < _relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)_relations[i] !).ChildKey)) { if (relation.ParentKey.ColumnsEqual(((DataRelation)_relations[i] !).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } } _relations.Add(relation); ((DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Add(relation); // Caching in ParentTable -> ChildRelations ((DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Add(relation); // Caching in ChildTable -> ParentRelations relation.SetDataSet(_dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint?foreignKey = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation._createConstraints) { if (foreignKey == null) { relation.ChildTable.Constraints.Add(foreignKey = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); // try to name the fk constraint the same as the parent relation: try { foreignKey.ConstraintName = relation.RelationName; } catch (Exception e) when(Common.ADP.IsCatchableExceptionType(e)) { ExceptionBuilder.TraceExceptionWithoutRethrow(e); } } } UniqueConstraint?key = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(key); relation.SetChildKeyConstraint(foreignKey); }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if ((relation.ChildTable.DataSet != this.dataSet) || (relation.ParentTable.DataSet != this.dataSet)) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation.relationName.Length == 0) { relation.relationName = base.AssignName(); } else { base.RegisterName(relation.relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < this.relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)this.relations[i]).ChildKey) && relation.ParentKey.ColumnsEqual(((DataRelation)this.relations[i]).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } this.relations.Add(relation); ((DataRelationCollection.DataTableRelationCollection)relation.ParentTable.ChildRelations).Add(relation); ((DataRelationCollection.DataTableRelationCollection)relation.ChildTable.ParentRelations).Add(relation); relation.SetDataSet(this.dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint constraint = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation.createConstraints && (constraint == null)) { relation.ChildTable.Constraints.Add(constraint = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); try { constraint.ConstraintName = relation.RelationName; } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ExceptionBuilder.TraceExceptionWithoutRethrow(exception); } } UniqueConstraint constraint2 = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(constraint2); relation.SetChildKeyConstraint(constraint); }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if (relation.ChildTable.DataSet != dataSet || relation.ParentTable.DataSet != dataSet) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation.relationName.Length == 0) { relation.relationName = AssignName(); } else { RegisterName(relation.relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation)relations[i]).ChildKey)) { if (relation.ParentKey.ColumnsEqual(((DataRelation)relations[i]).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } } relations.Add(relation); ((DataRelationCollection.DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Add(relation); // Caching in ParentTable -> ChildRelations ((DataRelationCollection.DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Add(relation); // Caching in ChildTable -> ParentRelations relation.SetDataSet(dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(relation); } ForeignKeyConstraint foreignKey = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumns, relation.ChildColumns); if (relation.createConstraints) { if (foreignKey == null) { relation.ChildTable.Constraints.Add(foreignKey = new ForeignKeyConstraint(relation.ParentColumns, relation.ChildColumns)); // try to name the fk constraint the same as the parent relation: try { foreignKey.ConstraintName = relation.RelationName; } catch { // ignore the exception } } } UniqueConstraint key = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumns); relation.SetParentKeyConstraint(key); relation.SetChildKeyConstraint(foreignKey); }
protected override void AddCore(DataRelation relation) { base.AddCore(relation); if ((relation.ChildTable.DataSet != this.dataSet) || (relation.ParentTable.DataSet != this.dataSet)) { throw ExceptionBuilder.ForeignRelation(); } relation.CheckState(); if (relation.Nested) { relation.CheckNestedRelations(); } if (relation.relationName.Length == 0) { relation.relationName = base.AssignName(); } else { base.RegisterName(relation.relationName); } DataKey childKey = relation.ChildKey; for (int i = 0; i < this.relations.Count; i++) { if (childKey.ColumnsEqual(((DataRelation) this.relations[i]).ChildKey) && relation.ParentKey.ColumnsEqual(((DataRelation) this.relations[i]).ParentKey)) { throw ExceptionBuilder.RelationAlreadyExists(); } } this.relations.Add(relation); ((DataRelationCollection.DataTableRelationCollection) relation.ParentTable.ChildRelations).Add(relation); ((DataRelationCollection.DataTableRelationCollection) relation.ChildTable.ParentRelations).Add(relation); relation.SetDataSet(this.dataSet); relation.ChildKey.GetSortIndex().AddRef(); if (relation.Nested) { relation.ChildTable.CacheNestedParent(); } ForeignKeyConstraint constraint = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference); if (relation.createConstraints && (constraint == null)) { relation.ChildTable.Constraints.Add(constraint = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference)); try { constraint.ConstraintName = relation.RelationName; } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ExceptionBuilder.TraceExceptionWithoutRethrow(exception); } } UniqueConstraint constraint2 = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference); relation.SetParentKeyConstraint(constraint2); relation.SetChildKeyConstraint(constraint); }