Jaa


Example Step 4: Modify the Class-to-Storage Mapping

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

This topic describes how to update the mapping between runtime objects and the database.

To update to OrderObjectMappings.xml file

  1. Create a copy of the OrderObjectMappings.xml file if you want to be able to revert to your original configuration. Edit the OrderObjectMappings.xml file to perform the rest of this procedure.

  2. Define a table for the VirtualGiftCertificate class, and name the table VirtualGiftCertificates. Within the Tables element, create a Table element and define the columns and constraints of the table.

    The Table element for the VirtualGiftCertificates table will look as follows:

    <Table Name="VirtualGiftCertificates">
        <Columns>
            <Column Name="VirtualGiftCertificateId" DataType="uniqueidentifier" />
            <Column Name="OrderFormId" DataType="uniqueidentifier" IsNullable="false" />
            <Column Name="OrderGroupId" DataType="uniqueidentifier" IsNullable="false" />
        </Columns>
        <Constraints>
            <PrimaryKey Name="PK_VirtualGiftCertificates">
                <ColumnRef Name="VirtualGiftCertificateId" />
            </PrimaryKey>
            <ForeignKey Name="FK_VirtualGiftCertificates_OrderForms" ForeignTable="OrderForms" CascadeDelete="false">
                <ColumnMatch Name="OrderFormId" ForeignName="OrderFormId" />
            </ForeignKey >
        </Constraints>
    </Table>
    

    Note

    You must define a foreign key because data in the VirtualGiftCertificates table will be referenced by data in another table, in this case the OrderForms table.

  3. Define the VirtualGiftCertificate class. Within the Classes element, create a Class element and define the properties of the class. You are only required to define the properties that you will map to the database.

    The Class element for the VirtualGiftCertificate class will look as follows:

    <Class Name="VirtualGiftCertificate">
        <Property Name="VirtualGiftCertificateId" />
        <Property Name="OrderGroupId" />
        <Property Name="OrderFormId" />
        ...
    </Class>
    
  4. Define the mapping between the VirtualGiftCertificate class and the VirtualGiftCertificates table. Within the Mappings element, create a ClassTableMap element and define the mappings between properties of the class and columns of the table.

    The ClassTableMap element for the mapping between the VirtualGiftCertificate class and the VirtualGiftCertificates table will look as follows:

    <ClassTableMap Class="VirtualGiftCertificate" Table="VirtualGiftCertificates">
        <PropertyMap Property="OrderGroupId" Column="OrderGroupId" />
        <PropertyMap Property="OrderFormId" Column="OrderFormId" />
        <PropertyMap Property="VirtualGiftCertificateId" Column="VirtualGiftCertificateId" />
        ...
    </ClassTableMap>
    
  5. Modify the mapping between the OrderForm class and the OrderForms table. Chane the name of the class from OrderForm to MyOrderForm.

    <ClassTableMap Class="MyOrderForm" Table="OrderForms">
        ...
    </ClassTableMap>
    
  6. Modify the Class element for the OrderForm class. Change the name of the class to "MyOrderForm", and add a property named GiftCertificates to represent the collection of virtual gift certificates.

    The Class element for the MyOrders class will look as follows:

    <Class Name="MyOrderForm">
        <Property Name="GiftCertificates"/>
        ...
    </Class>
    
  7. For each collection that involves the OrderForm class, change the collection relationship to use the MyOrderForm class instead.

    The modified CollectionRelationship elements will look as follows:

    <CollectionRelationship
        Name="OrderFormPayments"
        ParentClass="MyOrderForm"
        ParentProperty="Payments"
        ChildClass="Payment" />
    <CollectionRelationship
        Name="OrderFormLineItems"
        ParentClass="MyOrderForm"
        ParentProperty="LineItems"
        ChildClass="LineItem" />
    <CollectionRelationship
        Name="OrderFormShipments"
        ParentClass="MyOrderForm"
        ParentProperty="Shipments"
        ChildClass="Shipment" />
    <CollectionRelationship
        Name="OrderFormPromoCodeRecords"
        ParentClass="MyOrderForm"
        ParentProperty="PromoCodeRecords"
        ChildClass="PromoCodeRecord" />
    
  8. Define the relationship between an order form and a virtual gift certificate. Within the CollectionRelationships element, add a new CollectionRelationship element to represent the fact that an order form contains a collection of virtual gift certificates.

    The CollectionRelationship element that describes the relationship between the OrderForm class and the VirtualGiftCertificate class will look as follows:

    <CollectionRelationship
        Name="OrderFormGiftCertificates"
        ParentClass="MyOrderForm"
        ParentProperty="GiftCertificates"
        ChildClass="VirtualGiftCertificate" />
    
  9. Save the OrderObjectMappings.xml file.

See Also

Other Resources

Mapping Purchase Orders to the Database

Orders Example: Adding Virtual Gift Certificates