Share via


CS 2006 Orders: Are my 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 2006 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 2006 - 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.

Comments

  • Anonymous
    April 08, 2006
    Nihit,

    Excellent post. You should write the docs! (Sorry Adam, just kidding!) The docs are a little vague on how to persist weakly-typed properties to the tables and your post makes it perfectly clear!

    By the way, I think "weakly-typed" is a much more understandable term than "indexer". Most .NET developers understand strongly-typed objects and can easily understand an object which is not strongly typed (IE typed DataSets versus regular DataSets) but "indexer" brings back memories of COM+ dictionaries in pre .NET programming. Besides, an indexed property really is "weakly typed" isn't it?
  • Anonymous
    April 08, 2006
    Nihit Kaul [MSFT] has written an exceptionally clear and easy to understand post on how to use weakly-typed properties in the CS2006 Orders system.
  • Anonymous
    April 08, 2006
    The comment has been removed
  • Anonymous
    October 30, 2007
    Thanks for that. I could not find the doc for what to add to OrderObjectMappings.xml. All I had found was to change it, then run OrderMapping.exe Its not too hard, but its much more complicated than just adding a column with a matching name.