The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

Archive for September, 2007

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

Posted by Gerhard Stephan on 20th September 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

    {

        Active,

        Retired,

        Deleted

    }

 

    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>

        [Ignore]

        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.
Cheers

- Gerhard

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

New Release - AdFactum ObjectMapper .NET 1.90.1917.0

Posted by Gerhard Stephan on 17th September 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in Releases | No Comments »

Publication in the dot.net magazin

Posted by Gerhard Stephan on 13th September 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in Miscellaneous | No Comments »

How to use Generics with the AdFactum ObjectMapper .NET

Posted by Gerhard Stephan on 13th September 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »