[DevExpress Support Team: CLONED FROM T150240: Security: Persist changed properties only when saving a changed business object record]
the OptimisticLockField seems to be updated many times even if no other properties on the table have changed.
is there a way to change the behavior to only update that field if a property has changed?
It is unclear in what case the current OptimisticLockField behavior causes difficulties. Please describe the issue in greater detail and provide a small sample project demonstrating it.
we are investigating to use SQL Server Temporal Tables to replace the AuditTrail Module for a number of reasons.
After reading the Related Question to this one Auditing/Optimistic locks with collections and non-persistent properties
we have a console XAF app that imports Sales and Inventory. we have the Inventory item as a reference property on the salesorder. So in the import method, we set Sale.InventoryItem. if there is no association between them, would the OptimisticLockField still be updated on the Inventory Item?
and if so, is there a way to prevent it from happening?
Hello Scott.
The OptimisticLockField value is incremented before saving an object if it was marked as modified.
If an association is not declared, changing the value of a reference property won't mark the assigned object as modified. You can verify this by examining the collection returned by the Session.GetObjectsToSave method.
Also note that calling the Session.Save or XPBaseObject.Save method marks the object as modified even if none of its properties were changed.
To determine why an object is unexpectedly marked as modified, override its OnChanged method (or subscribe to the Session.ObjectChanged event), set a breakpoint in it, and examine the call stack when the method is entered.
I think calling Save might be it, I'll Review the code and let you know.
ok, that was some older code.
if contact.Phone == phone, would the object be marked as modified?
public static void UpdateContact(IObjectSpace os, string name,string phone) { Person contact = os.GetObjectsQuery<Person>(true) .SingleOrDefault(p => p.FirstName == name) ?? os.CreateObject<Person>(); contact.Phone = phone; os.CommitChanges(); }
Since this code modifies the Phone property of the "contact" (Person) object, the object is marked as modified (if its properties are implemetned accordign to the Unit of Work article).
Let me know if you need any additional assistance.