Until now it was the job of the database server to maintain data relationships, but with the flexibility of ADO.NET, now programmers can also create and maintain data relationships in a disconnected environment. A data relationship relates two tables to each other through their columns—for example, a customer/order relationship. The Customers table stores records of a customer, and the Orders table stores records of orders made by customers. Each customer has only one record in the Customers table, which is identified by a unique column value called Customer Id. Each order is related to a customer, which has a column that stores the customer ID. The Orders table can have multiple records for a single customer. In this scenario, the Customer Id row in the Customers table acts as a parent row, and all related rows in the Orders table act as its child rows. One condition in this example is that the data type of both the parent and row columns must be identical.
In ADO.NET, the DataRelation class represents a data relation between two DataTable objects, and the DataRelationCollection represents a collection of data relations.
In a connected environment, you can access and maintain data relations through a DataSet. The Relations property of the DataSet returns a collection of data relations associated with that DataSet in the form of a DataRelationCollection object. The ChildRelations and ParentRelations properties of a DataTable return the child relations and parent relations associated with that DataTable.
As you know from "The DataRow" section of Chapter 3, the DataRow also provides methods to return a row's parent and child rows. The GetParentRow method of a DataRow returns the parent row of a DataRow, and the GetParentRows method returns all parent rows related to a DataRow. The GetChildRows method returns all the child rows associated with a DataRow.