Chapter 11. DataRelations

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.

Get ADO.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.