Ticket T140736
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How to generate UPDATE statements including changed values only

GetPropertiesListForUpdateInsert - How to select modified fields ?

created 11 years ago

Hello.

Thanks to Dennis (DevExpress Support) , he give me info about GetPropertiesListForUpdateInsert in ticket T120279
I can exclude some fields by name (code below)

C#
C#
public class UpdatedFieldsUnitOfWork : UnitOfWork { public UpdatedFieldsUnitOfWork(IDataLayer dataLayer) : base(dataLayer) {} protected override MemberInfoCollection GetPropertiesListForUpdateInsert(object theObject, bool isUpdate, bool addDelayedReference) { MemberInfoCollection result = new MemberInfoCollection(this.GetClassInfo(theObject)); foreach (XPMemberInfo mi in base.GetPropertiesListForUpdateInsert(theObject, isUpdate,addDelayedReference)) { // DON'T WORK: if (mi is ServiceField || mi.GetModified(theObject)) //WORK BELOW if (mi is ServiceField || !(mi.Name == "fLastUser")) result.Add(mi); } return result; } }

But I want to update only modified fields.

Trying to filter by

C#
mi.GetModified(theObject)

But it always return False;

How can I filter it ?

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello Andrey,
By default, property modifications are not tracked. The Session.TrackPropertiesModifications property specifies whether or not the current Session tracks persistent object property modifications.
The default value of the TrackPropertiesModifications property is taken from the static XpoDefault.TrackPropertiesModifications property.
When TrackPropertiesModifications is set to true, field-level optimistic locking is enabled. Its behavior can be configured via the OptimisticLockingAttribute attribute and the OptimisticLockingReadBehavior property.
You can enable/disable property tracking for each persistent type individually by applying the OptimisticLockingReadBehaviorAttribute attribute. This attribute overrides the TrackPropertiesModifications setting of the Session.
Please note that to support this functionality, persistent properties should be implemented in a specific manner:
SetPropertyValue("PropertyName", ref propertyValueHolder, value);So, you just need to set the TrackPropertiesModifications property to true.
Please let me know if you need further assistance.

    Comments (2)

      Great! Thank you.
      It works.
         public class UpdatedFieldsUnitOfWork : UnitOfWork {
             public UpdatedFieldsUnitOfWork(IDataLayer dataLayer): base(dataLayer) {
                     this.TrackPropertiesModifications = true;
             }
      Optimistic Locking = True ( On persistent object in Orm model)/

      DevExpress Support Team 11 years ago

        You're welcome.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.