Using the OptimizedUpdateDataEntity features

When sending objects over to the IntegrationFramework you do not need to populate every property of each BusinessObject (i.e RetailItem, RetailDepartment etc). Those classes inherit the OptimizedUpdateDataEntity class which allows you to only update the fields in the underlying database table that you populate on the BusinessObject. This allows you to only update a subset of existing columns without populating the entire object.

This topic goes through a simple example showing which methods you need to use from the OptimizedUpdateDataEntity base class.

RetailItem example

Let's say that you only want to update the Description and ExtendedDescription properties of a retail item without changing any other fields. To do this you could use the following code:

RetailItem itemToUpdate = new RetailItem();                            
itemToUpdate.ID = "60110";
itemToUpdate.Text = "Booyah dishwasher";                            
itemToUpdate.ExtendedDescription = "The greatestest dishwasher ever";
((IOptimizedUpdate)itemToUpdate).CloneUpdateListToTransportList();
wcfRetailItemService.Save(CreateLogonInfo(dataModel), itemToUpdate);

Looking at each line of code, below is an explanation of what is happening in each line:

Code

Explanation

itemToUpdate.ID = "60110";

Sets the ID of the item to update. You must always populate the fields that represent either the primary key of the underlying table, or the fields that are used as the conditions of the SqlServerStatement in the underlying DataProvider.

Those fields should be documented on each class.

itemToUpdate.Text = "Booyah dishwasher";

itemToUpdate.ExtendedDescription = "The greatestest dishwasher ever";

Here we update only the properties we want to change. The RetailItem class will call the AddColumnInfo function from OptimizedUpdateDataEntity to make sure that only the corresponding columns in the RETAILITEM table are to be updated.
((IOptimizedUpdate)itemToUpdate).CloneUpdateListToTransportList(); This will clone the current list of fields that should be updated. This is required since the original list will get lost when the object is serialized and deserialized when sent over WCF.
wcfRetailItemService.Save(CreateLogonInfo(dataModel), itemToUpdate); Finally this sends the object over to the IntegrationFramework service. The service will then restore the original ColumnUpdateList to make sure that only the Description and ExtendedDescription fields are updated in the RETAILITEM table.

Since RetailItem inherits the OptimizedUpdateDataEntity it allows you to have very granular control over which data you wish to update in the RETAILITEM table. This is especially useful if you are integrating an ERP system which might not have all the retail-specific fields of the retail item.