Creating a New Class Relation

This section describes how to create a parent-child relation between classes in the Data Warehouse. The classes for the relation and the key for the parent class must exist prior to creating the relation. The relation name must be unique.

Ee796329.note(en-US,CS.20).gifNotes****

  • Member names in inheritance-type relations should not be duplicated in the parent and child classes because all the parent class members are visible in the child class.
  • For one-to-many relations, the parent key member names should not be duplicated in the child class for the same reason.
  • Two classes should only have one relation defined between them.
  • If the IsPersistent attribute of a class is set to zero (0), and the class is then defined to be a parent class, the value of the IsPersistent attribute of the class is changed to one (1) by the OLE DB Provider for Commerce Server.
  • For information about creating classes and keys, see Creating a New Class and Creating a New Class Key, respectively.

A class relation is created by creating a new instance of a Relation Definition (reldef), populating the attributes, and saving the changes. For information about the Relation Definition table, see Relation Definition Meta-data.

We continue our example (which originated in Creating a New Class) by creating a one-to-many (type 2) relation between the existing OrderGroup class and the "new" OrderFormHeader class. For details about these classes, see OrderGroup and OrderFormHeader. By creating this relation to an existing Data Warehouse class, we are linking to the logical schema. Linking to the existing logical schema is not necessary for extending the Data Warehouse.

The following table lists the attributes and values in the Relation Definition table for the relation between the OrderGroup and OrderFormHeader classes. Unspecified optional attributes are not shown. In the R/O column, R = required, O = optional.

Attribute name Attribute value Type R/O Purpose
RelationName "OrderGroupToOrderFormHeader" String R Uniquely identifies the relation between the classes.
RelType 2 Integer R Defines the type of relation. The most common is type "2", which is one-to-many.
ParentClassName "OrderGroup" String R Identifies the parent class in the parent-child relation.
ParentClassKey "OrderGroupKey" String R Identifies the key for the parent class.
ChildClassName "OrderFormHeader" String R Identifies the child class in the parent-child relation.
Description "OrderGroup to OrderFormHeader relation." String O Describes the relation.

Running Example - Step 6

Create a relation linking the OrderFormHeader class to the OrderGroup class.

Ee796329.note(en-US,CS.20).gifNote

  • The code provided in this example is for demonstration purposes only. The OrderFormHeader class created in this example already exists in the Data Warehouse schema. The CreateSchemaObject.vbs file included in the Commerce Server 2002 Software Development Kit should be used to automate the process of extending the schema. For more information about the script, see Create Schema Object Script.
'Create an instance in the Relation Definition table.
   recNew.Open "Relation/OrderGroupToOrderFormHeader", cnnConnection, _
     adModeWrite, adCreateOverwrite

'Set the required attributes.
   recNew("ParentClassName") = "OrderGroup"
   recNew("ParentClassKey") = "OrderGroupKey"
   recNew("ChildClassName") = "OrderFormHeader"
   recNew("RelType") = 2
   recNew("Description") = "OrderGroup to OrderFormHeader relation."

'Save the new row.
   recNew("__Commit") = 1
   recNew.Fields.Update
   recNew.Close

Repeat the process above to add relations between the OrderFormHeader class and other classes (such as the Date class for the existing logical schema). The next step is to create a member relation between specific data members in the parent and child classes to be used as the foreign key for the OrderFormHeader class.

See Also

Creating a New Class Relation Member

Create Schema Object Script

Copyright © 2005 Microsoft Corporation.
All rights reserved.