The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

Archive for November, 2006

Attribute: [WeakReferenced]

Posted by Gerhard Stephan on 20th November 2006

The WeakReferenced Abbtribute forces the mapper to use outer joins when joining parent and child table using Virtual Links.

This attribute is always useful if the child property is not a mandatory property of the parent class.

Think about a contact object that has a mandatory firstname and lastname and a salutation enumeration. The salutation enumeration is not mandatory.

    /// <summary>

    /// Descripes a contact

    /// </summary>

    [Table("CONTACTS")]

    public class Contact : ValueObject

    {

        private Salutation salutation;

        private string salutationText;  // get text from db using a virtual link

 

        private string firstName;

        private string lastName;

 

        /// <summary>

        /// Gets or sets the salutation.

        /// </summary>

        /// <value>The salutation.</value>

        public Salutation Salutation

        {

            get { return salutation; }

            set { salutation = value; }

        }

 

        /// <summary>

        /// Gets or sets the salutation text.

        /// </summary>

        /// <value>The salutation text.</value>

        [VirtualLink(typeof(SalutationText), "Value", "Key", "Salutation")]

        public string SalutationText

        {

            get { return salutationText; }

            set { salutationText = value; }

        }

 

        /// <summary>

        /// Gets or sets the name of the first.

        /// </summary>

        /// <value>The name of the first.</value>

        [Required]

        [PropertyLength(50)]

        public string FirstName

        {

            get { return firstName; }

            set { firstName = value; }

        }

 

        /// <summary>

        /// Gets or sets the name of the last.

        /// </summary>

        /// <value>The name of the last.</value>

        [Required]

        [PropertyLength(50)]

        public string LastName

        {

            get { return lastName; }

            set { lastName = value; }

        }

    }

 

The salutation enumeration looks like this:

    /// <summary>

    /// Salutation

    /// </summary>

    public enum Salutation

    {

        None,

       

        DearMr,

        DearMrs,

        MyFriend

    }

 

And last but not least, the text corresponding to that enumeration will be retrieved by a virtual link using database joins.

 

    /// <summary>

    /// Static texts for salutation

    /// </summary>

    [StaticData]

    [WeakReferenced]

    public class SalutationText : ValueObject

    {

        private Salutation  key;

        private string      value;

 

        public Salutation Key

        {

            get { return key; }

            set { key = value; }

        }

 

        public string Value

        {

            get { return value; }

            set { this.value = value; }

        }

    }

 

When selecting the contact the SQL looks like that:

SELECT contacts.*, v1.VALUE AS salutationtext

  FROM contacts LEFT OUTER JOIN salutationtext v1 ON contacts.salutation = v1.KEY

 

If you wouldn’t use the attribute [WeakReferenced] a contact without a filled salutation could not be loaded. 
Because of that issue the attribute is very important.

1 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 5 (1 votes, average: 5 out of 5)
Loading ... Loading ...

Posted in Attributes | 1 Comment »

New Release - ObjectMapper .NET 1.4.1014.0

Posted by Gerhard Stephan on 14th November 2006

 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 »

New Release - ObjectMapper .NET 1.3.1002.0

Posted by Gerhard Stephan on 2nd November 2006

 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 »