Chapter 10
showed how to
use ForeignKeyConstraint
rules to help ensure the
integrity of relational data. Though
ForeignKeyConstraint
objects are important for
data validation, they don’t provide any benefit when
it comes to navigating the DataSet
. For example,
even if you define a link between two tables with a
ForeignKeyConstraint
, you can’t
use this link to create a master-detail list.
ADO.NET provides another object that can help in this situation: the
DataRelation
. You can use a
DataRelation
to automatically generate and apply a
ForeignKeyConstraint
, or you can use it simply as
a navigational aid. The benefit of the
DataRelation
is that it allows you to navigate
disconnected data using a defined relationship between tables. For
example, if you select a single parent row, you can use the
DataRelation
to retrieve a list of child records.
Conversely, you can use the DataRelation
to
discover the parent of any child row.
This chapter explains how to create a
DataRelation
, use it for
record
navigation, and build a master-detail list.