DataRelation Object Reference
The reference information for the DataRelation object isn't terribly interesting, to be honest. The object exposes no methods and no eventsonly properties. However, to leave these out would somehow feel like cheating.
Properties of the DataRelation Object
Most of the DataRelation object's properties are read-only. You can set their value only using the DataRelation object's constructors. The commonly used properties are described in Table 7-1.
Property | Data Type | Description |
ChildColumns | Array of DataColumn objects | Indicates the child columns that define the relation. This property is read-only. |
ChildKeyConstraint | ForeignKeyConstraint | Indicates the foreign key constraint in the child table in the relation. This property is read-only. |
ChildTable | DataTable | Indicates the child table in the relation. This property is read-only. |
DataSet | DataSet | Indicates the DataSet in which the DataRelation resides. This property is read-only. |
ExtendedProperties | PropertyCollection | Indicates a collection of dynamic properties. |
Nested | Boolean | Indicates whether the child rows are child elements when the DataSet is stored as XML. |
ParentColumns | Array of DataColumn objects | Indicates the parent columns that define the relation. This property is read-only. |
ParentKeyConstraint | UniqueConstraint | Indicates the unique constraint in the parent table in the relation. This property is read-only. |
ParentTable | DataTable | Indicates the parent table in the relation. This property is read-only. |
RelationName | String | Indicates the name of the relation. |
ChildColumns Property
The ChildColumns property returns an array that contains the DataColumn object or objects from the child DataTable in the DataRelation. This property is read-only.
ChildKeyConstraint Property
The ChildKeyConstraint property returns the ForeignKeyConstraint referenced by the DataRelation. If you created a DataRelation that does not use constraints, this property returns Nothing or null, depending on your language of choice. The ChildKeyConstraint property is read-only.
ChildTable Property
The ChildTable property returns the child DataTable in the DataRelation. This property is read-only.
DataSet Property
The DataSet property returns the DataSet in which the DataRelation resides. This property is read-only.
ExtendedProperties Property
Like the DataSet, DataTable, and DataColumn objects, the DataRelation object also exposes an ExtendedProperties property in which you can store additional information.
Nested Property
The Nested property controls the location of the contents of the child DataTable when the DataSet is stored in XML format using the DataSet object's WriteXml method. This is one of the few read-write properties of the DataRelation object.
If the Nested property is set to False, which is the default, the data in the child DataTable will be separate from the data in the parent DataTable. As you can see here, without looking at the schema information for the DataSet, you wouldn't know that there is a DataRelation between the DataTable objects:
Not Nested
<Customers> <CustomerID>ALFKI</CustomerID> <CompanyName>Alfreds Futterkiste</CompanyName> </Customers> <Customers> <CustomerID>ANATR</CustomerID> <CompanyName>Ana Trujillo Emparedados y helados</CompanyName> </Customers> ... <Orders> <OrderID>10308</OrderID> <CustomerID>ANATR</CustomerID> </Orders> <Orders> <OrderID>10355</OrderID> <CustomerID>AROUT</CustomerID> </Orders> ...
Setting the Nested property to True causes ADO.NET to embed the data in the child DataTable within the data for the parent DataTable, as shown here:
Nested
<Customers> <CustomerID>ALFKI</CustomerID> <CompanyName>Alfreds Futterkiste</CompanyName> <Orders> <OrderID>10643</OrderID> <CustomerID>ALFKI</CustomerID> </Orders> <Orders> <OrderID>10692</OrderID> <CustomerID>ALFKI</CustomerID> </Orders> ... </Customers> <Customers> <CustomerID>ANATR</CustomerID> <CompanyName>Ana Trujillo Emparedados y helados</CompanyName> <Orders> <OrderID>10308</OrderID> <CustomerID>ANATR</CustomerID> </Orders> <Orders> <OrderID>10625</OrderID> <CustomerID>ANATR</CustomerID> </Orders> ... </Customers> ...
ParentColumns Property
The ParentColumns property returns an array that contains the DataColumn objects from the parent DataTable in the DataRelation. This property is read-only.
ParentKeyConstraint Property
The ParentKeyConstraint property returns the UniqueConstraint referenced by the DataRelation. If you created a DataRelation that does not use constraints, this property returns Nothing or null, depending on your language of choice. The ParentKeyConstraint property is read-only.
ParentTable Property
The ParentTable property returns the parent DataTable in the DataRelation. This property is read-only.
RelationName Property
The RelationName property is read-write and can be used to set or retrieve the name of the DataRelation.