A newer version of this page is available. Switch to the current version.

OptimisticLockingAttribute Class

Specifies that a persistent object's state can be locked during a session.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v18.2.dll


[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = true)]
public sealed class OptimisticLockingAttribute :
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Interface, Inherited:=True)>
Public NotInheritable Class OptimisticLockingAttribute
    Inherits Attribute


The OptimisticLockingAttribute attribute specifies whether a session can lock a persistent object's state (allows optimistic locking to be enabled). To control object locking for objects that have the object locking option enabled, a new system field called by default OptimisticLockField is added to the object table's structure during the database schema update.

In optimistic concurrency, locks are set and held only while the data store is being accessed. The locks prevent other users from attempting to update objects at the same time. When an update is attempted, the original version of a changed object is compared against the existing object in the data store. If the two are different, the update fails with a concurrency error. It is up to you at that point to reconcile the two objects using your business logic.

Use the Session.LockingOption property to control the persistent object's locking during a session.

Use the Session.TrackPropertiesModifications property to enable field-level locking.

For more information, see Optimistic Concurrency Control.


This attribute affects service member generation (see When and Why XPO Extends the Database Schema). If it needs to be applied to a dynamically created class, pass this attribute in the XPDictionary.CreateClass method arguments instead of adding it afterwards.


See Also