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); }
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 != 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); }
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); }