Represents a parent/child relationship between two System.Data.DataTable objects.
See Also: DataRelation Members
A System.Data.DataRelation is used to relate two System.Data.DataTable objects to each other through System.Data.DataColumn objects. For example, in a Customer/Orders relationship, the Customers table is the parent and the Orders table is the child of the relationship. This is similar to a primary key/foreign key relationship. For more information, see Navigating a Relationship between Tables.
Relationships are created between matching columns in the parent and child tables. That is, the DataColumn.DataType value for both columns must be identical.
Relationships can also cascade various changes from the parent System.Data.DataRow to its child rows. To control how values are changed in child rows, add a System.Data.ForeignKeyConstraint to the System.Data.ConstraintCollection of the System.Data.DataTable object. The System.Data.ConstraintCollection determines what action to take when a value in a parent table is deleted or updated.
When a System.Data.DataRelation is created, it first verifies that the relationship can be established. After it is added to the System.Data.DataRelationCollection, the relationship is maintained by disallowing any changes that would invalidate it. Between the period when a System.Data.DataRelation is created and added to the System.Data.DataRelationCollection, it is possible for additional changes to be made to the parent or child rows. An exception is generated if this causes a relationship that is no longer valid.
Data corruption can occur if a bi-directional relation is defined between two tables. A bi-directional relation consists of two DataRelation objects that use the same columns, with the parent-child roles switched. No exception is raised when the DataRelation objects are saved; however, data corruption can occur.
System.Data.DataRelation objects are contained in a System.Data.DataRelationCollection, which you can access through the DataSet.Relations property of the System.Data.DataSet, and the DataTable.ChildRelations and DataTable.ParentRelations properties of the System.Data.DataTable.