AdFactum ObjectMapper .NET Blog

Official blog of the AdFactum ObjectMapper .NET

How to do bind collections

Posted by Gerhard Stephan on August 24th, 2006

The ObjectMapper .NET offers different possibilities to map collections to database. All different solutions have pro and contras. This post shall lighten those pros and contras in order to give you the ability to choose the proper solution for your use case.

General IList Binding:

        private IList contacts = new ArrayList();

        public IList Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

 

Pro:

  • You can add all objects to the List that are derived from IValueObject.

Contra:

  • You can’t use foreign key constraints.
  • The performance is worse, compared to other solutions, because the List can contain all type of objects. Perhaps the ObjectMapper .NET has to read from multiple tables.

Bound IList Binding:

        private IList contacts = new ArrayList();

 

        [BindPropertyTo(typeof(Contact))]

        public IList Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

 

Pro:

  • You get best performance, because the ObjectMapper .NET knows which objects you expect.
  • The ObjectMapper .NET creates foreign key constraints.
  • You get a better data integrity due to the use of foreign key constraints.

Contra:

  • It’s only possible to store objects of the type you specified.

Generic List Binding:

        private List<Contact> contacts = new List<Contact>();

 

        public List<Contact> Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

Pro:

  • You get best performance, because the ObjectMapper .NET knows which objects you expect.
  • The ObjectMapper .NET creates foreign key constraints.
  • You get a better data integrity due to the use of foreign key constraints.

Contra:

  • It’s only possible to store objects of the type you specified.

General Generic List Binding:

        private List<Contact> contacts = new List<Contact>();

 

        [GeneralLink]

        public List<Contact> Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

Pro:

  • You can add all objects to the List that are derived from the type you specified.

Contra:

  • You can’t use foreign key constraints.
  • The performance is worse, compared to other solutions, because the list can contain all types derived from the type you specified. Perhaps the ObjectMapper .NET has to read from multiple tables.

Important

Using the current version of the ObjectMapper .NET it’s not possible to bind generic IList<T> collections. This is because the generic IList<T> interface does not support the IList interface. We try to offer this feature as soon as possible.

So forget about the following example; it will produce failures:

 

        private IList<Contact> contacts = new List<Contact>();

 

        public IList<Contact> Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

 

2 Responses to “How to do bind collections”

  1. Official ObjectMapper .NET Blog » Blog Archive » Attribute: [BindPropertyTo] Says:

    […] Additionally you will find useful informations in blog entry How to do bind collections. (No Ratings Yet)  Loading … […]

  2. AdFactum ObjectMapper .NET Blog » Blog Archive » Attribute: [GeneralLink] Says:

    […] Additionally have a look at the blog entry "How to do bind collections" (No Ratings Yet)  Loading … […]

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>