Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Defining Master Detail Relationships

Generally, you will want to express relationships that exist in your database. For example, if we want to include the Order Details table in our Schema, we can drag and drop the Order Details table onto the OrderDetails element. In fact, for our example, go ahead and drag and drop both Order Details and Products onto the Order Details element. The Schema Designer will define a Schema with three tables. (If we were to generate the code at this point, we would have a DataSet with three tables with no relationships expressed.) The results should look similar to those shown in Figure 4.

Figure 4Figure 4 A Schema with three tables.

Relationships are logical in a database, and there are several ways to capture logical relationships in code or the database. You could create a view in the database to capture the logical relationship between Orders, Order Details, and Products. You could write a heterogeneous query, joining these three tables by keys, or take advantage of new technology.

The new prescribed method of expressing logical relationships is to add disparate yet logically related tables to a single DataSet and then add DataRelations to the DataSet. The net benefit is that the tables are distinct and can be modified, which is something you can't do with a view, yet you can present the data in a manner that is consistent with their logical relationships.

You define a DataRelation in the Schema by selecting a key in one table element and picking Schema, Add, New Relation from the main menu. This step opens the Edit Relation dialog box (shown in Figure 5). Complete the relationship definition by filling out the Edit Relation dialog box. Parent and child elements are the related tables, and the fields are the primary and foreign key in the respective tables.

Figure 5Figure 5 The Edit Relation dialog box defines the DataRelation object that will be generated by the Schema Designer.

Use Figure 6 as a visual guide and define a relationship for Orders and Order Details and Order Details and Products.

Figure 6Figure 6 The Schema Designer can be viewed as analogous to an entity relationship diagram.

  • + Share This
  • 🔖 Save To Your Account