AdFactum ObjectMapper .NET Blog

Official blog of the AdFactum ObjectMapper .NET

How to check if a property has been changed since last loading the object.

Posted by Gerhard Stephan on September 20th, 2007

Sometimes it’s important for the business logic to know if the UI changed a special property since last loading the object. Maybe this is important for the workflow or other things. Using the AdFactum ObjectMapper .NET you can use a speical pattern for that.

Have a look at the following example. The entity Company has a state called CompanyState. We now want to know, whether that property has been changed by the UI since last loading the object. Therefore we need a second property that holds the orginal value. This property is filled the first time wehn the object is loaded by the AdFactum ObjectMapper .NET. A property with the Ignore attribute checks those two properties to indicate whether the property has been changed or not. It’s important to define the orginal value as a nullable type, because we only want to fill that property the first time when the setter is called.

    public enum CompanyState







    public class Company


        private CompanyState companyState;

        private CompanyState? orgCompanyState = null;


        /// <summary>

        /// Gets or sets the state of the company.

        /// </summary>

        /// <value>The state of the company.</value>

        public CompanyState CompanyState


            get { return companyState;  }

            set {

                companyState = value;

                if (orgCompanyState == null)

                    orgCompanyState = value;




        /// <summary>

        /// Gets a value indicating whether the company state changed or not.

        /// </summary>

        /// <value><c>true</c> if company state changed; otherwise, <c>false</c>.</value>


        public bool CompanyStateChanged


            get { return companyState != orgCompanyState;  }




In our business logic we can now check the CompanyStateChanged property and react on new values within the company state. E.g. send emails or do something else.

That’s all for now.

– Gerhard

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>