AdFactum ObjectMapper .NET Blog

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

Posted in HowTo | No Comments »

New Release – AdFactum ObjectMapper .NET 1.90.1917.0

Posted by Gerhard Stephan on 17th September 2007

The new release of the AdFactum ObjectMapper .NET covers several enhancements that have been discussed in other thread within this blog.

First of all the OBM (ObjectMapper .NET Manager Class) has been included in the current release. That means that you don’t have to implement multi threading functionality by your own. You can simple use the OBM helper class. The original idea of the OBM has been explained in Tutorial 4. The only difference is, that the signature of the Method CreateMapper has been changed.

public static ObjectMapper CreateMapper(DatabaseConnection connection)

The DatabaseConnection Property specifies the Database to that the ObjectMapper .NET connects to. I’m going to write further blog entries in order to explain the new OBM class.

Furthermore I replaced the class BaseFactory with the new UniversalFactory. This class covers the the changes from the blog entry "A Final performance boost" which unleash incredible performance when loading many objects. To enable this performance boost your entities have to implement the ICreateObject interface.

    public interface ICreateObject

    {

        /// <summary>

        /// Creates the new object.

        /// </summary>

        /// <returns></returns>

        IValueObject CreateNewObject();

    }

 

As third improvement I re-worked all classes that implements the IDisposable interface in order to use the correct IDisposable Pattern.

Last but not least, I fixed the bug "[ 1793851 ] OrderBy does not generate parenthesis". The problem was that SQL Statements misses parenthesis within the ORDER BY clause. Which is very bad if you are using reserved words like INDEX.

That’s all for now.
Cheers

– Gerhard

Posted in Releases | No Comments »

Publication in the dot.net magazin

Posted by Gerhard Stephan on 13th September 2007

The dot.net magazin published an article about the AdFactum ObjectMapper .NET in their current 10/2007 issue.

October 2007 issue of the dot.net magazin

This time I wrote the article by my own – so I can’t say thanks to someone 😉
My concern of this article was to bring some light into the dark that surrounds the ORM.

Hope that you’ll have a look at the article and provide me with some feedback.

Wish you a nice week 
Cheers

– Gerhard

Posted in Miscellaneous | No Comments »

How to use Generics with the AdFactum ObjectMapper .NET

Posted by Gerhard Stephan on 13th September 2007

It’s not a surprise, but worth to say: The AdFactum ObjectMapper .NET does fully supports the Generics of the dotNet Framework 2.0. Having a first look at the interface of the ObjectMapper class, nothing looks like, that Generics can be used.

For Example: public IList FlatSelect(Type type)

Most of all, this is because of the backward compatibility to the dotNet Framwork 1.0. But let us have a look at the following use case.

List<User> users = new List<User>(

new ListAdapter<User>(

   mapper.FlatSelect(typeof (User), userCondition)));

 

The AdFactum ObjectMapper .NET provides a helper class called ListAdapter to bridge the gap between the untyped IList interface and the Generics, used by the dotNet Framework 2.0. The base principles of the ListAdapter can be found here.

That’s all for now.
Cheers

Gerhard

Posted in HowTo | No Comments »