Show/Hide Toolbars

TMS Aurelius Documentation

Navigation: Mapping

Automapping

Scroll Prev Top Next More

Automapping is an Aurelius feature that allows you to save a class without needing to specify all needed mapping attributes. Usually in an entity class you need to define table where data will be saved using Table attribute, then for each field or property you want to save you need to specify the Column attribute to define the table column in the database where the field/property will be mapped to, etc..

 

By defining a class as automapped, a lot of this mapping is done automatically based on class information, if it's not explicity specified. For example, the table name is automatically defined as the class name, with the "T" prefix removed.

 

To define a class as automapped, you just need to add the Automapping attribute to the class.

 

Automapping is not an all-or-nothing feature. Aurelius only performs the automatic mapping if no attribute is specified. For example, you can define a class as automapped, but you can still declare the Table attribute to specify a different table name, or you can use Column attribute in some specific fields or properties to override the default automatic mapping.

 

Below we list some of rules that automapping use to perform the mapping.

 

Table mapping

 

The name of table is assumed to be the name of the class. If the first character of the class name is an upper case "T", it is removed. All letters become uppercase and upcase characters in the middle of the name are preceded by underline. For example, class "TCustomer" will be mapped to table "CUSTOMER", and class "TMyInvoice" will be mapped to table "MY_INVOICE"

 

Column mapping

 

Every field in the class is mapped to a table column. Properties are ignored and not saved. If you don't want a specific class field to be saved automatically, add a Transient attribute to that class field.

 

The name of the table column is assumed to be name of the field. If the first character of the field name is an upper case "F", it is removed. All letters become uppercase and upcase characters in the middle of the name are preceded by underline. For example, field "FBirthday" is mapped to table column "BIRTHDAY" and field "FFirstName" is mapped to table column "FIRST_NAME".

 

If the class field type is a Nullable<T> type, then the table column will be optional (nullable). Otherwise, the table column will be required (NOT NULL).

 

For currency fields, scale and precision are mapped to 4 and 18. For float fields, scale and precision are mapped to 8 and 18, respectively. If field is a string, length used will be the default length specified in the global configuration.

 

If the field is an object instance instead of an scalar value/primitive type, then it will be mapped as an association, see below.

 

Associations

 

If the class field in an object instance (except a list), it will be mapped as an association to that class. The column name for the foreign key will be the field name (without "F") followed by "_ID". For example, if the class has a field

 

FCustomer: TCustomer 

 

Aurelius will create an association with TCustomer and the name of table column holding the foreign key will be "Customer_ID".

 

If the class field is a list type (TList<T>) it will be mapped as a many-valued association. A foreign key will be created in the class used for the list. The name of table column holding the foreign key is field name + table name + "_ID". For example, if class TInvoice has a field:

 

FItems: TList<TInvoiceItem>

 

Aurelius will create a many-valued association with TInvoiceItem, and a table column holding the foreign key will be created in table "InvoiceItem", with the name "Items_Invoice_ID".

 

If the field type is a Proxy<T> type, fetch type of the association will be defined as lazy, otherwise, it will be eager.

 

Identifier

 

If no Id attribute is specified in the class, Aurelius will use a field named "FID" in the class as the class identifier. If such class field does not exist and no Id attribute is defined, an error will be raised when the class is saved.

 

Enumerations

 

Enumerations are not automapped unless the auto mapping mode is configured to Full in global configuration. In this case, if an enumeration type does not have an Enumeration attribute defined, it will be automapped as string type, and the mapped value will be the name of the enumerated value. For example, the enumerated type:

 

TSex = (seFemale, seMale);

 

will be mapped as string with mapped values 'seFemale', 'seMale'.

 

Sequences

 

If not specified, the name of the sequence to be created/used (if needed) will be "SEQ_" + table name. Initial value and increment will defined as 1.

 

Inheritance

 

Inheritance is not automapped and if you want to use it you will need explicitly define Inheritance attribute and the additional attributes needed for complete inheritance mapping.