Example Step 2: Modify the Class-to-Storage Mapping
This topic describes how to update the mapping between runtime objects and the database.
To update to OrderObjectMappings.xml file
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.
Update the table that stores instances of the extended class to add a column for the new property. For this example, add a new Column element to the LineItems table. Provide the following attributes:
Name
Value
Name
"WidgetDescriptionProperty"
DataType
"nvarchar"
Precision
"64"
IsNullable
"true"
The Table element for the LineItems table will look as follows:
<Table Name="LineItems"> <Columns> <Column Name="WidgetDescriptionProperty" DataType="nvchar" Precision="64" IsNullable="true" /> ... </Columns> </Table>
Update the name of the class. For this example, change the name of the LineItem Class element to "MyLineItem".
The Class element for the MyLineItem class will look as follows:
<Class Name="MyLineItem"> ... </Class>
Add the new property to the class. Within the MyLineItem Class element, add a Property element whose Name attribute has the value "WidgetDescriptionProperty".
The Class element for the MyLineItem class will look as follows:
<Class Name="MyLineItem"> <Property Name="WidgetDescriptionProperty"/> ... </Class>
Change every collection of LineItem objects to a collection of MyLineItem objects. For this example, change the value of the ChildClass attribute from "LineItem" to "MyLineItem" in the OrderFormLineItems CollectionRelationship.
The CollectionRelationship element for the LineItems in an OrderForm will look as follows:
<CollectionRelationships> <CollectionRelationship Name="OrderFormLineItems" ParentClass="OrderForm" ParentProperty="LineItems" ChildClass="MyLineItem" /> ... </CollectionRelationships>
Change every collection that was contained in a LineItem object to be contained in a MyLineItem object. For this example, change the value of the ParentClass attribute from "LineItem" to "MyLineItem" in the LineItemDiscountsApplied and ItemLevelDiscountsApplied CollectionRelationship elements.
The CollectionRelationship elements for the discounts on a LineItem will look as follows:
<CollectionRelationship Name="LineItemDiscountsApplied" ParentClass="MyLineItem" ParentProperty="OrderLevelDiscountsApplied" ChildClass="DiscountApplicationRecord" /> <CollectionRelationship Name="ItemLevelDiscountsApplied" ParentClass="MyLineItem" ParentProperty="ItemLevelDiscountsApplied" ChildClass="DiscountApplicationRecord" />
Change the mapping between the class and the table. For this example, change the value of the Class attribute from "LineItem" to "MyLineItem" in the ClassTableMap for the LineItems table.
The ClassTableMap element for the LineItems table will look as follows:
<ClassTableMap Class="MyLineItem" Table="LineItems"> ... </ClassTableMap>
Update the mapping between the class and the table to add a mapping for the new property. For this example, add a new PropertyMap element to the mapping you modified in the previous step. Provide the following attributes:
Name
Value
Property
"WidgetDescriptionProperty"
Column
"WidgetDescriptionProperty"
The ClassTableMap element for the WidgetDescriptionProperty property will look as follows:
<ClassTableMap Class="MyLineItem" Table="LineItems"> <PropertyMap Property="WidgetDescriptionProperty" Column="WidgetDescriptionProperty" /> </ClassTableMap>
Save the OrderObjectMappings.xml file.