What Are the Restrictions on Mapping Class Container Relationships?
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.
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:
One class cannot contain another class both directly and indirectly (that is, through another class).
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).
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.
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" />