Bagikan melalui


What Are the Restrictions on Mapping Class Container Relationships?

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

The CollectionRelationship element of the OrderObjectMappings.xml file specifies that one class contains a collection of objects that belong to another class. If class A contains objects of class B, you can use the CollectionRelationship element to map the relationship between classes A and B. The following illustration shows this relationship.

Class A contains class B

For example, if A is the PurchaseOrder class and B is the OrderForm class, you can describe the relationship between the two classes in the following way:

<CollectionRelationship
  Name="PurchaseOrderOrderForms"
  ParentClass="PurchaseOrder"
  ParentProperty="OrderForms"
  ChildClass="OrderForm" />

The previous example indicates that the OrderForms property of the PurchaseOrder class contains a collection of OrderForm objects.

There are two restrictions on how you can map classes to database tables when one class contains another:

  1. One class cannot contain another class both directly and indirectly (that is, through another class).

  2. Even if one class is contained in another class through multiple paths, you can map the contained class to only one table.

The following sections describe these restrictions in more detail.

Class Containment Relationships

In the following illustration, class C is contained in class A both directly and indirectly (through class B).

Class A contains class C directly and indirectly

This relationship is not allowed. One class cannot be contained in another class both directly and indirectly.

Relationships through Multiple Paths

In the following illustration, class B is contained in class A in two ways.

Class A contains class B in two ways

This relationship is allowed. However, class B must be mapped to only one table.

For example, assume that A is the LineItem class and B is the DiscountApplicationRecord class. DiscountApplicationRecord objects are contained in LineItem objects through two paths:

  • DiscountApplicationRecord objects that relate to a line item are accessed through the LineItem.ItemLevelDiscountsApplied property.

  • DiscountApplicationRecord objects that relate to the order as a whole are accessed through the LineItem.OrderLevelDiscountsApplied property.

The following example shows both relationships between the two classes.

<CollectionRelationship
  Name="LineItemDiscountsApplied"
  ParentClass="LineItem"
  ParentProperty="OrderLevelDiscountsApplied"
  ChildClass="DiscountApplicationRecord" />
<CollectionRelationship
  Name="ItemLevelDiscountsApplied"
  ParentClass="LineItem"
  ParentProperty="ItemLevelDiscountsApplied"
  ChildClass="DiscountApplicationRecord" />

See Also

Other Resources

Mapping Purchase Orders to the Database

Orders Mapped Storage