AdFactum ObjectMapper .NET Blog

Official blog of the AdFactum ObjectMapper .NET

Archive for October, 2007

New Release – AdFactum ObjectMapper .NET 2.0.2129.0

Posted by Gerhard Stephan on 30th October 2007

Today I’m proud to release version 2.0 of the AdFactum ObjectMapper .NET. This major release covers new key features like a first LINQ implementation, new projection classes and several bug fixes regarding the XML persister.

First of all, the ObjectMapper .NET does now understand the basic LINQ syntax. Please keep in mind that this is a first implementation and that it does not cover the complete functionality of LINQ. But it’s a first step. Be sure that the next release of the ObjectMapper .NET will cover a lot more LINQ features than it does today.

Linq Support

var orders = mapper.Query<Order>();

var customers = mapper.Query<Customer>();

 

var mexicanOrders =

from order in orders

join customer in customers on order.Customer equals customer

where customer.Country == "Mexico"

select order;

 

You’ll find several LINQ examples within the NUnit Test Cases.  

Anonymous Types

Because the dotNet Framework 3.0 does now support anonymous types, the AdFactum ObjectMapper .NET had to support these types in order to be LINQ conform.  Have a look at the following LINQ query.

var mexicanOrders =
      from order in orders
      join customer in customers on order.Customer equals customer
      where customer.Country == "Mexico"
           
select new {
                  customer.CompanyName,
                  customer.ContactName,
                  order.OrderDate,
                  order.ShipName };

 

The result of this query is a list with objects of an anonymous type. The anonymous type has four properties (CompanyName, ContactName, OrderDate and ShipName).

Projection class

The support of anonymous types leads to a new feature of the AdFactum ObjectMapper .NET. It was a absolute necessity to add an equal feature to the non LINQ version. That new feature has been called projection classes. A projection class is a class where the properties are used to mirror the results of multiple sources into one projection. 

     /// <summary>
    /// Class used for projections
    /// A class that is used for projects must not be a ValueObject!
    /// </summary>

    public class OrderCustomer
    {
        private string companyName;
        private string contactName;
        private string shipName;

        /// <summary>
        /// Gets or sets the company name.
        /// </summary>
        /// <value>The company name.</value>
        [ProjectOntoProperty(typeof(Customer), "CompanyName")]
        public int CompanyName
        {
            get { return companyName; }
            set { companyName = value;  }
        }

        /// <summary>
        /// Gets or sets the contact name.
        /// </summary>
        /// <value>The contact name.</value>
        [ProjectOntoProperty(typeof(Customer), "ContactName")]
        public string ContactName
        {
            get { return contactName; }
            set { contactName = value; }
        }

        /// <summary>
        /// Gets or sets the ship name.
        /// </summary>
        /// <value>The name of the ship.</value>
        [ProjectOntoProperty(typeof(Order), "ShipName")]
        public string ShipName
        {
            get { return shipName; }
            set { shipName = value; }
        }
    }

EXAMPLE:

List<OrderCustomer> names = new List<OrderCustomer>(
      new ListAdapter<OrderCustomer>(
            mapper.Select(typeof (OrderCustomer),
            new Join(typeof (Order), “Customer”, typeof (Customer))));

 

Support of .NET 2003 closed

Because of all these new features and changes it wasn’t possible to keep the .NET 2003 support for the AdFactum ObjectMapper .NET. I hope that not many users are still working with .NET 2003, but there had not been an other solution. Due to this change, it’s necessary to de-install the ObjectMapper .NET first, before installing the new version. 

XML Persister

The Xml Persister has been greatly reworked. It’s now again possible to store object trees into an XML File. I say "again", because this features has been broken in one of the last versions of the AdFactum ObjectMapper .NET.  

Minor Bug Fixes

Last but not least, there have been many minor bug fixes.

  1. There were failures when defining primary keys other than already defined in the base classes, like ValueObject or AutoIncValueObject.
  2. The Access Persister did not throw the correct error number the time a failure occured. This forced the AccessPersister to execute the SQL multiple times before throwing an exception.
  3. Furthermore I implemented a new caching strategy which reduced the amount of cache access significantly.

And a lot of more minor bug fixes / changes that are not counted.

Hope you enjoy the new version.

Cheers
– Gerhard 

kick it on DotNetKicks.com

Posted in Releases | No Comments »

Hierarchy Level Explained

Posted by Gerhard Stephan on 1st October 2007

The AdFactum ObjectMapper .NET uses hierarchy levels to define the degree of dependence that will be considered when loading or saving.

When loading with hierarchy level 0, the object will be loaded into memory without any dependencies. The same happens when the AdFactum ObjectMapper.NET is storing the objects to database. That means HierarchyLevel.FlatObject, loading and storing without any object dependencies.

For load operations the hierachy level step is always 2.

        public const int FlatObject = 0;

        public const int Dependend1stLvl = 2;

        public const int Dependend2ndLvl = 4;

        public const int AllDependencies = int.MaxValue;

 

In the following example you can see the object dependencies when loading the customer object.

 

For example, when loading the customer with HierarchyLevel.Dependent1stLvl the aggregated Order Objects will be loaded too. When loading the customer with HierarchyLevel.Dependent2ndLvl the OrderItems of the Order Object will be also loaded.

When storing objects to database the Hierarchy Level is even more senstive. That means that you can also specify, whether an object should only update the links to an aggregated object or whether the object should also update the aggregated object too.

These are the intermediate steps 1, 3, 5 and so on. That is, if you only add an existing OrderItem to the Order object, you can store the Order Object with the HierarchyLevel.FlatObjectWithLinks, which updates the link to the OrderItem, but not the OrderItem itself. The difference is very important to know.

For load operations the hierachy level step is always 1.

        public const int FlatObject               = 0;

        public const int FlatObjectWithLinks      = 1;

        public const int Dependend1stLvl          = 2;

        public const int Dependend1stLvlWithLinks = 3;

        public const int Dependend2ndLvl          = 4;

        public const int Dependend2ndLvlWithLinks = 5;

        public const int AllDependencies          = int.MaxValue;

 

In the following example you can see the object dependencies when storing the customer object.

 

For a better understanding I recommend you to output the SQL trace and try to store the object with a different hierarchy levels. That gives you a feeling for, which hierarchy level you use best to get the optimal performance.

 

Posted in Hint | No Comments »