The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

New Release – ObjectMapper .NET 1.60.1517.1

Posted by Gerhard Stephan on April 17th, 2007

Today I’m proud to present the new major release of the AdFactum ObjectMapper .NET.  This release includes two new features and one major attribute change.

As a new feature I extended the join condition in order to enable joining objects with objects, types with objects and types with types. Thus reduces the amount of conditions that are necessary to limit the database query.

Imagine we have a structure like that:

            Employee emp = new Employee("All", "Mine");

            FullFeaturedCompany c1 = new FullFeaturedCompany("Heavy stuff");

            c1.Owner = emp;

            FullFeaturedCompany c2 = new FullFeaturedCompany("Light stuff");

            c2.Owner = emp;

 

            Employee emp2 = new Employee("Thats", "not mine");

            FullFeaturedCompany c3 = new FullFeaturedCompany("Other stuff");

            c3.Owner = emp2;

 

Now you have several possibilities to join these Company -> Employee structure.

 

            /*

             * Join company c1 object with owner object

             */

            FullFeaturedCompany loaded;

            loaded = (FullFeaturedCompany) Mapper.FlatLoad(typeof (FullFeaturedCompany),

                new Join(c1, "Owner", emp));

            Assert.AreEqual(c1.Id, loaded.Id, "Could not load company");

 

            /*

             * Join typeof(Company) with owner object

             */

            IList selection;

            selection = Mapper.FlatSelect(typeof (FullFeaturedCompany),

                new Join(typeof (FullFeaturedCompany), "Owner", emp));

            Assert.AreEqual(2, selection.Count, "Could not find the 2 expected companies.");

 

            /*

             * Join typeof(Company) with typeof(Employee)

             */

            selection = Mapper.FlatSelect(typeof(FullFeaturedCompany),

                new Join(typeof(FullFeaturedCompany), "Owner", typeof(Employee)));

            Assert.AreEqual(3, selection.Count, "Could not find the 3 expected companies.");

 

 

As a second new feature I extended the InCondition. In prior versions the InCondition could only use SubSelects or Unions to build IN Condition SQL statements. Now it’s possible to give value arrays or value lists to the ObjectMapper .NET in order to support queries like "field IN (value1, value2, … valueN)".

 

            /*

             * Insert some test contacts

             */

            BeginTransaction();

            Mapper.Save(new Contact("Fritz", "Bauer"));

            Mapper.Save(new Contact("Annemarie", "Aal"));

            Mapper.Save(new Contact("Hans", "Habicht"));

            Mapper.Save(new Contact("Olaf", "Schubert"));

            Commit();

 

            /*

             * Search "Annemarie" and "Olaf" using the InCondition

             */

            InCondition condition = new InCondition(typeof(Contact), "FirstName", "Annemarie", "Olaf");

            IList result = Mapper.Select(typeof (Contact), condition);

 

.. or

            InCondition condition = new InCondition(typeof(Contact), "FirstName", "Annemarie", "Olaf", "Fritz");

 

You can also put a IList object into the InCondition. This enables you to use a generic collection e.g. List<string> in order to provide the values for the InCondition.

 

The biggest changes have been made for the ForeignKey Attribute. In prior versions the foreign key attribute has been a class attribute. Because this wasn’t really generic, I changed the ForeignKey attribute handling so that it can now be used like the Unique attribute. Compound Foreign Keys can now set with Key Groups. So have a look at the following example.

 

        [PropertyLength(32)]

        [ForeignKey(1, typeof(Country), "Key")]

        public string CountryKey

        {

            get { return countryKey; }

            set { countryKey = value; }

        }

 

        [PropertyLength(5)]

        [ForeignKey(1, typeof(Country), "Locale")]

        public new string Locale

        {

            get { return base.Locale; }

            set { base.Locale = value; }

        }

 

This example creates a compound foreign key to the Country object. 

 

That’s all for now. So hope you enjoy the new version of the ObjectMapper .NET.

Cheers

 

- Gerhard

 

 http://www.objectmapper.net/download/ObjectMapper_1.60.1517.1.exe

kick it on DotNetKicks.com

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=""> <strike> <strong>