Name
DataRelation
Synopsis
A DataRelation represents a parent-child relation
between two tables. A DataSet stores
DataRelation objects in its
DataRelationCollection object. These
DataRelation objects must be created
programmatically, even if they are defined in the data source.
ADO.NET data providers automatically determine relationships from the
data source.
There are two reasons to add a DataRelation
object. The first is make navigation easier. Once you have created
the relation, you can use methods such as
DataRow.GetChildRows( ) and
DataRow.GetParentRow( ) to retrieve related rows.
The second reason is to enforce relational constraints. When you
create a relation, a corresponding
ForeignKeyConstraint is generated by default and
added to the table. As long as
DataSet.EnforceConstraints is set to
true, an exception is thrown when you attempt to
perform an action that violates the relationship (such as adding a
child that refers to a nonexistent parent).
The easiest way to create a DataRelation is to use
the constructor that requires the relation name, the parent
DataColumn, and the child
DataColumn. Alternatively, you can relate
multiple columns or use an overloaded version that allows you to
prevent the creation of the ForeignKeyConstraint.
public class DataRelation { // Public Constructors public DataRelation(stringrelationName, DataColumn[ ]parentColumns, DataColumn[ ]childColumns); public DataRelation(stringrelationName, DataColumn[ ]parentColumns, DataColumn[ ]childColumns ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access