Adding References to a Class

When you have defined your collection subclasses and dictionary class keys, the Define References sheet of the External Schema Wizard then enables you to add references to your external database classes. References added to a class are based on any foreign keys defined for or by the class member tables, or by an association of arbitrary columns. Foreign keys represent one-to-one and one-to-many relationships. Primary keys determine the object identity for a class formed by the union of tables.

A reference property is a one relationship and a collection property is a many relationship. If a property defining the relationship is not a collection, only one reference is allowed. The collection can be a set, an array, or a dictionary.

An example of the Define References sheet of the External Schema Wizard is shown in the following image.

The Left Side Class combo box and the Right Side Class list box list all of the ExternalObject subclasses defined for your external database schema, to enable you to select the classes between which to define a relationship. The Left Side Class combo box also includes the external relational database class that corresponds to this external database schema, to enable you to define a root object reference.

The tables at the right of the sheet represent the two classes that you select. The tables display a section for each relational table defined for the selected classes (by using the Define Classes sheet, in an earlier step). These sections list the columns of the tables.

Columns that participate in the primary key of the table are indicated with a bitmap, as are columns that participate in a foreign key and those that participate in both types of key. A dotted (broken) line drawn between these two tables indicates a candidate relationship. A solid line indicates a relationship that you have already defined.

The types of relationship that can be shown are listed in the following table.

Relationship Description
Foreign key-based Uses primary and foreign key information from the relational database to determine the columns that are involved
Name-based Matches columns with the same name and similar types, to identify potential relationships
User-defined Relies on you to select the columns that are involved in the relationship

If a relationship uses several columns on one side of the relationship, these columns are bracketed. A directional arrow on a line indicates the relationship from a foreign key to a primary key.

A relationship line that already has a defined reference is displayed with a 1 or M character at each end of the line, indicating the cardinality of the relationship; that is, one or many.

To specify a reference

  1. In the Left Side Class combo box, specify or select the class for the left-hand side of the relationship.

  2. In the Right Side Class list box, select the class for the right-hand side of the relationship.

  3. Click on the line that represents a candidate relationship.

    Alternatively, if you want to define a relationship that is not automatically generated as a candidate relationship, perform the following actions.

    1. In the first table, select the column or columns that are to form one end of the reference.

    2. In the second table, select the column or columns that you want to form the other end of the reference.

  4. Click the Add button.

Alternatively, to specify an arbitrary relationship, you can drag-and-drop between a single column in each table, or you can select multiple compatible columns with the same type in the same order and then click the Add button.

The External Schema Wizard Relationship dialog is then displayed, to enable you to define your reference.

To edit an existing reference

  1. Click the relationship line between the two references. The selected line is then displayed in white. You can select only one relationship line at any time.

  2. Click the Edit button.

The External Schema Wizard Reference dialog is then displayed, to enable you to change the existing reference. For details, see "Using the External Schema Wizard Relationship Dialog", in the following subsection.

To delete an existing reference

  1. Click the relationship line between the two references.

  2. Click the Remove button.

The references between the two classes are then removed.

To proceed to the next step of the schema transformation process

When you click the Next > button, the External Schema Wizard then enables you to refine your external database schema class SQL queries.