// // System.Data.DataRelation.cs // // Author: // Daniel Morgan // Alan Tam Siu Lung // Tim Coleman // // (C) 2002 Daniel Morgan // (C) 2002 Ximian, Inc. // Copyright (C) Tim Coleman, 2003 // // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.ComponentModel; using System.Runtime.Serialization; namespace System.Data { /// /// DataRelation is used for a parent/child relationship /// between two DataTable objects /// [Editor ("Microsoft.VSDesigner.Data.Design.DataRelationEditor, " + Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)] [DefaultProperty ("RelationName")] #if !NET_2_0 [Serializable] #endif [MonoTODO] [TypeConverterAttribute (typeof (RelationshipConverter))] public class DataRelation { private DataSet dataSet; private string relationName; private UniqueConstraint parentKeyConstraint; private ForeignKeyConstraint childKeyConstraint; private DataColumn[] parentColumns; private DataColumn[] childColumns; private bool nested; internal bool createConstraints; private PropertyCollection extendedProperties; private PropertyChangedEventHandler onPropertyChangingDelegate; #region Constructors public DataRelation (string relationName, DataColumn parentColumn, DataColumn childColumn) : this(relationName, parentColumn, childColumn, true) { } public DataRelation (string relationName, DataColumn[] parentColumns, DataColumn[] childColumns) : this(relationName, parentColumns, childColumns, true) { } public DataRelation (string relationName, DataColumn parentColumn, DataColumn childColumn, bool createConstraints) : this(relationName, new DataColumn[] { parentColumn }, new DataColumn[] { childColumn }, createConstraints) { } public DataRelation (string relationName, DataColumn[] parentColumns, DataColumn[] childColumns, bool createConstraints) { this.extendedProperties = new PropertyCollection(); if (relationName == null) relationName = string.Empty; this.relationName = relationName; if (parentColumns == null) throw new ArgumentNullException (); this.parentColumns = parentColumns; if (childColumns == null) throw new ArgumentNullException (); this.childColumns = childColumns; this.createConstraints = createConstraints; if (parentColumns.Length != childColumns.Length) throw new ArgumentException ("ParentColumns and ChildColumns should be the same length"); DataTable parentTable = parentColumns[0].Table; DataTable childTable = childColumns[0].Table; if (parentTable.DataSet != childTable.DataSet) throw new InvalidConstraintException (); foreach (DataColumn column in parentColumns) if (column.Table != parentTable) throw new InvalidConstraintException (); foreach (DataColumn column in childColumns) if (column.Table != childTable) throw new InvalidConstraintException (); for (int i=0; i /// Check whether the given column is part of this relation. /// /// /// true if the column is part of this relation, otherwise false. /// internal bool Contains (DataColumn column) { foreach (DataColumn col in ParentColumns) if (col == column) return true; foreach (DataColumn col in ChildColumns) if (col == column) return true; return false; } #endregion // Methods } }