Share via


SetDirty Method

Updates local and parent change information and allows automatic validation of the specified property data.

Namespace:  Microsoft.CommerceServer.Runtime
Assembly:  Microsoft.CommerceServer.Runtime (in Microsoft.CommerceServer.Runtime.dll)

Syntax

'Declaration
Public Overridable Sub SetDirty ( _
    propertyValue As Object _
)
'Usage
Dim instance As MappedStorageBase
Dim propertyValue As Object

instance.SetDirty(propertyValue)
public virtual void SetDirty(
    Object propertyValue
)
public:
virtual void SetDirty(
    Object^ propertyValue
)
public function SetDirty(
    propertyValue : Object
)

Parameters

  • propertyValue
    Type: System..::.Object
    The value provided to the property set accessor. Can be nullNothingnullptra null reference (Nothing in Visual Basic) if SetDirty is being called from outside a property setter context, or if a property setter handles its own property length validation.

Remarks

SetDirty must be implemented by non-collection classes that map to storage. It must be called by property set accessors and other internal class logic when values that map to storage are updated. propertyValue is the value provided to the property set accessor. This function serves several purposes:

  • It allows the local class to update its own "last modified" DateTime property (if present) in a common fashion.

  • When implemented according to guidelines (provided below), it ensures that modification date updates propagate to parent classes by calling SetChildDirty on each parent.

  • It allows the storage implementation to optimize SQL update queries to minimize thrashing and the amount of data marshaled and sent across the network.

  • It allows the storage system to support optimistic concurrency in the site database.

  • When used with StorageLoadInProgress, it ensures that LastModified times are not updated while loading from storage.

  • When propertyValue is non nullNothingnullptra null reference (Nothing in Visual Basic), it allows the orders system to validate string lengths against an nvarchar length specified in the mapping for the corresponding column. Note that this functionality is for ease of use, but may cause some performance degradation relative to user-performed length validation in the property setter.

The base class implementation, which should be called from overrides, performs the automatic validation steps. An override version is responsible for updating any local "last modified" DateTime stamp, and for calling the parent object's SetParentDirty implementation.

Examples

SetDirty should follow the following general code template in order to provide consistency with the implementations of existing orders classes.

using Microsoft.CommerceServer.Runtime;
class MyClass : MappedStorageBase
{
  void SetDirty(object propertyValue)
  {
    // Check to see if StorageLoadInProgress is set - if so, skip
    // processing of this call.
    if (!StorageLoadInProgress)
    {
      // Call the base class function to perform automatic validation
      // of the property
      // value. This call can throw an exception if validation
      // determines that the
      // provided value is outside allowed ranges set for the
      // relational schema.
      // For example, when a string value is set that is longer than
      // the precision
      // set on the underlying storage. This call would not be made if
      // user-defined code
      // performs its own validation.
      base.SetDirty(propertyValue);
      // If there is a local DateTime property that stores a "last
      // modified" time,
      // update it here with the current time (DateTime.Now).
      // Update it with local time if the field is mapped to storage - 
      // it will be
      // converted to UTC during marshaling. If there is such a field,
      // be sure to cache
      // the DateTime.Now value in a local variable, use the value to
      // set the local property,
      // and pass the value to the parent through the other overloaded
      // version of
      // SetChildDirty().
      // If this class is contained within a parent (e.g. an OrderForm
      // or OrderGroup),
      // notify that parent instance of a change in this class. Use the
      // overload that
      // contains DateTime if we generated a local DateTime.
      if (this.myParentRef != null)
        this.myParentRef.SetChildDirty();
    }
  }
} 

Permissions

See Also

Reference

MappedStorageBase Class

MappedStorageBase Members

Microsoft.CommerceServer.Runtime Namespace