Freigeben über


Are my Orders indexer properties saved to the database? Where? How?

Indexer properties (or weakly-typed properties as they are sometimes referred to - I can see Cathy, our doc writer, cringing on the mention of this term which she passionately abhors) are present on almost all the common Orders classes in CS 2007 such as OrderGroup (which is the base type for Basket, PurchaseOrder and OrderTemplate classes), OrderForm, LineItem etc. One common operation that customers typically have done is to store certain values in an indexer property and store it to the database. This is still the case and all you need to do is save the OrderGroup class containing everything to the database to have this persisted.

E.g. (pseudo code):

myOrder.OrderForms[0].LineItems[0]["myCustomData"] = "Some biz data";
myOrder.Save();

Now when myOrder is reload from the database the "myCustomData" property on the LineItem on which it was set, will still be present.

By default these properties are all saved to the marshalled_data column in their respective tables and this should suffice for most purposes. However if you wish to persist these indexer properties to an explicit column of their own, you can do this in 2 steps:

  1. Update the mapping file sections and add an explicit column, name of the indexer property and the mapping between the property and the column storing it's value. E.g. (partially XML snippets from the OrderObjectMappings.xml):

    <Table Name="LineItems">
    <Columns>
    <Column Name=" myCustomData" DataType="nvarchar" Precision="128" IsNullable="true" />

    <Class Name="LineItem">
    <WeaklyTypedProperty Name="myCustomData" />

    <ClassTableMap Class="LineItem" Table="LineItems">
    <PropertyMap Property="myCustomData" Column="myCustomData" />

Create the associated SQL schema changes (either manually or by using the OrderMapping.exe tool to generate the SQL table definitions and stored procedure definitions for you - these include drop statements so use this carefully).

Now when you run your site code which populates these indexer properties, you should be able to see the indexer property values getting persisted into their own SQL columns. Not too hard is that?

And if you like that, wait till you try out the full fledged extensibility story in Commerce Server 2007 - it not only allows you to map all PurchaseOrder data to explicit columns but also allows you to inherit from all the Orders runtime class and extend it in order to define a much richer and fine-tuned-to-your-business Order system for use in your site code.