The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

Archive for the 'Attributes' Category

Attribute: [Unicode]

Posted by Gerhard Stephan on 7th March 2008

For all databases that supports Unicode (e.g. Oracle and Microsoft SQL Server),  a string property can be tagged with the [Unicode] attribute. The AdFactum ObjectMapper .NET does therefore use the Unicode Data Types for the specific property.

Below you’ll find all supported datatypes that can be used with the Unicode attribute.

    public class UnicodeTestEntity : ValueObject

    {

        private char unicodeChar;

        private string unicodeString;

        private string unicodeMemo;

 

        /// <summary>

        /// Gets or sets the unicode char.

        /// </summary>

        /// <value>The unicode char.</value>

        [Unicode]

        public char UnicodeChar

        {

            get { return unicodeChar; }

            set { unicodeChar = value; }

        }

 

        /// <summary>

        /// Gets or sets the unicode string.

        /// </summary>

        /// <value>The unicode string.</value>

        [Unicode]

        [PropertyLength(30)]

        public string UnicodeString

        {

            get { return unicodeString; }

            set { unicodeString = value; }

        }

 

        /// <summary>

        /// Gets or sets the unicode memo.

        /// </summary>

        /// <value>The unicode memo.</value>

        [Unicode]

        [PropertyLength(int.MaxValue)]

        public string UnicodeMemo

        {

            get { return unicodeMemo; }

            set { unicodeMemo = value; }

        }

    }

 

 

 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 Attributes | No Comments »

Attribute: [GroupBy]

Posted by Gerhard Stephan on 7th March 2008

The [GroupBy] attribute can be used to group properties by there value. This property can only be used in projection classes.

    /// <summary>

    /// Groups the time entries by their project id

    /// </summary>

    public class TimeEntryGrouping

    {

        private DateTime minDate;

        private string project;

 

        /// <summary>

        /// Gets or sets the min date.

        /// </summary>

        /// <value>The first date.</value>

        [ProjectOntoProperty(typeof(TimeEntry), "StartDate")]

        [Min]

        public DateTime MinDate

        {

            get { return minDate; }

            set { minDate = value; }

        }

 

        /// <summary>

        /// Gets or sets the project.

        /// </summary>

        /// <value>The project.</value>

        [ProjectOntoProperty(typeof(TimeEntry), "ProjectId")]

        [GroupBy]

        public string Project

        {

            get { return project; }

            set { project = value;  }

        }

    }

 

Select the grouping:

 

                List<TimeEntryGrouping> result =

                    new List<TimeEntryGrouping>(

                        new ListAdapter<TimeEntryGrouping>(

                    mapper.FlatSelect(typeof(TimeEntryGrouping))));

 

 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 Attributes | No Comments »

Attribute: [Avg], [Count], [First], [Last], [Max], [Min] and [Sum]

Posted by Gerhard Stephan on 7th March 2008

This aggregation attributes can be placed on any projection property of a projection class.

    public class TimeEntryAggregation

    {

        private DateTime minDate;

 

        /// <summary>

        /// Gets or sets the min date.

        /// </summary>

        /// <value>The first date.</value>

        [ProjectOntoProperty(typeof(TimeEntry), "StartDate")]

        [Min]

        public DateTime MinDate

        {

            get { return minDate; }

            set { minDate = value; }

        }

    }

    var minTimeEntry = mapper.Load(typeof(TimeEntryAggregation), null as ICondition) as TimeEntryAggregation;

 
The following attributes can be used this way:

  • [Avg] 
  • [Count]
  • [First], [Last]
  • [Min], [Max]
  • [Sum]
 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 Attributes | No Comments »

Attribute: [View]

Posted by Gerhard Stephan on 18th January 2008

This attribute can be used to define that a class is mapped to a database view.

      [View („VW_CONTACTS“)]

      public class Contact : ValueObject

 

The attribute is important for the Persisters, because some selects will fired in a different way, if you query a database view. If you want to map a database table, you can use the attribute called "Table".

 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 Attributes | No Comments »

Attribute: [ProjectOntoProperty]

Posted by Gerhard Stephan on 12th November 2007

The attribute [ProjectOntoProperty] is used to build projections of distinct source tables.

Defintion:

  1. A projection is a result subset of the queried tables.
  2. A projection can be used as a query result, instead of quering an IValueObject type.

That implicates, that a projection class (that uses the ProjectOntoProperty) must not implement the IValueObject interface.

Example:

Imagine you would have two value object types: A Company with their employees. Now you wanto to query the employees. As an additional information you want to output the name of the company where the employees are working. Because of this, you would have a a result type that is compound of the type company and employee.

List<FullFeaturedEmployee> names = new List<FullFeaturedEmployee>(

      new ListAdapter<FullFeaturedEmployee>(

            mapper.Select(

                  typeof(FullFeaturedEmployee),

                  new CollectionJoin(

                        typeof(Company),

                        "Employees",

                        typeof(Employee)

                  )

            )));

 

    /// <summary>

    /// Projects results of the company legalname and the employee names

    /// </summary>

    public class FullFeaturedEmployee

    {

        private int companyId;

        private int employeeId;

 

        private string companyName;

        private string firstName;

        private string lastName;

 

        [ProjectOntoProperty(typeof(Company), "LegalName")]

        public string CompanyName

        {

            get { return companyName; }

            set { companyName = value; }

        }

 

        [ProjectOntoProperty(typeof(Employee), "FirstName")]

        public string FirstName

        {

            get { return firstName; }

            set { firstName = value; }

        }

 

        [ProjectOntoProperty(typeof(Employee), "LastName")]

        public string LastName

        {

            get { return lastName; }

            set { lastName = value; }

        }

 

        [ProjectOntoProperty(typeof(Company), "Id")]

        public int CompanyId

        {

            get { return companyId; }

            set { companyId = value; }

        }

 

        [ProjectOntoProperty(typeof(Employee), "Id")]

        public int EmployeeId

        {

            get { return employeeId; }

            set { employeeId = value; }

        }

    }

 

Important:

A projection class (that uses the ProjectOntoProperty) must not implement the IValueObject interface.

 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 Attributes | No Comments »

Attribute: [DefaultValue]

Posted by Gerhard Stephan on 13th July 2007

The attribute [DefaultValue] can be used to specify a default value for a property. The [DefaultValue] attribute only affects the creation of the DDL file where a DEFAULT value is added to the field definition of the database.

        [PropertyLength(100)]

        [DefaultValue("Unkown Company")]

        public string LegalName

        {

            get { return legalName; }

            set { legalName = value; }

        }

The resulting field definition would be:

	LegalName VARCHAR(100) DEFAULT ‘Unkown Company’;
 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 Attributes | No Comments »

Attribute: [GeneralLink]

Posted by Gerhard Stephan on 11th June 2007

The attribute [GeneralLink] is the opposite of the attribute [BindPropertyTo]. It binds a property to a general class with an unspecified type. Therefore the type name of the bind object will be stored in an additional column. The name of that type column is calculated by the column name of the bound property added with a "#TYP".

        /// <summary>

        /// Gets or sets the contacts.

        /// </summary>

        /// <value>The contacts.</value>

        [GeneralLink(typeof(Contact))]

        public IList Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

All objects that are stored within that collection, must be derived of the class "Contact" or must be objects of that type.

        /// <summary>

        /// Gets or sets the person.

        /// </summary>

        /// <value>The person.</value>

        [GeneralLink(typeof(IPerson))]

        public IPerson Person

        {

            get { return person; }

            set { person = value; }

        }

 

All objects that are stored in property "Person", must implement the interface "IPerson".

        /// <summary>

        /// Gets or sets the contacts.

        /// </summary>

        /// <value>The contacts.</value>

        [GeneralLink]

        public IList Contacts

        {

            get { return contacts; }

            set { contacts = value; }

        }

 

        /// <summary>

        /// Gets or sets the person.

        /// </summary>

        /// <value>The person.</value>

        [GeneralLink]

        public IPerson Person

        {

            get { return person; }

            set { person = value; }

        }

Note: If no base class has been specified, "ValueObject" will be taken as the base type for the linked objects. Therefore all objects that will be stored within that collection must be derived from the class "ValueObject".

Additionally have a look at the blog entry "How to do bind collections"

 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 Attributes | No Comments »

Attribute: [PrimaryKey]

Posted by Gerhard Stephan on 11th June 2007

The property PrimaryKey can be used to tag a property that acts as a primary key column for the mapped table. In our classes ValueObject and AutoIncValueObject the Id Property has this attribute already assigned. Therefore this is only important if you write your own base classes or you define interfaces that shall be mapped.

    /// <summary>

    /// Interface that describes a person

    /// </summary>

    public interface IPerson : IValueObject

    {

        /// <summary>

        /// Gets or sets the unique value object id.

        /// </summary>

        /// <value>The unique value object id.</value>

        [PrimaryKey]

        new int? Id

        {

            get;

            set;

        }

 

 

Note: Combined primary keys are not allowed using the AdFactum ObjectMapper .NET.

Hint: It’s also valid to tag the primary key property with additional attributes, like [PropertyName] or [PropertyLength] to change the database binding.

 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 Attributes | 1 Comment »

Attribute: [VirtualLink]

Posted by Gerhard Stephan on 7th May 2007

The Virtual Link functionality is the most powerful feature the AdFactum ObjectMapper .NET offers.

What are Virtual Links?

Using Virtual Links you can implement objects that acts like database views. This enables you to join directly the values of your foreign key tables to your business entity.

What is the advantage?

The advantage is, that you don’t need to re-load Foreign Key Tables in order to get the display value of a foreign key. This saves you one SQL re-load per foreign key, and this without any further overhead.

If you are using the translation functionality of the AdFactum ObjectMapper .NET, the display values are already translated into your favoured language.

How can I use Virtual Links?

You can tag properties of your class with the [VirtualLink] attribute. Properties that are tagged with that attribute are only relevant when loading the entity. But they will be ignored when storing the entity to database.

        /// <summary>

        /// Department Key

        /// </summary>

        [PropertyName("DEPARTMENT")]

        [PropertyLength(4)]

        public string DepartmentKey

        {

            get { return departmentKey; }

            set { departmentKey = value; }

        }

 

        /// <summary>

        /// Department Text