Show/Hide Toolbars

TMS Aurelius Documentation

Specify the Identifier of the class.

 

Level: Class Attribute

 

Description

Every object must be uniquely identified by Aurelius so that it can properly save and manage it. The concept is similar to a primary key in database. This attribute allows you to specify which field (or property) in the class will be used to uniquely identify the class. The value of that field/property must be unique for every object, and you can specify how that value will be generated for each object.

In addition, if you are creating the database structure from the mapped classes, Aurelius will create a primary key in the database corresponding to the field/column mapping.

If you are using inheritance, you must only declare the Id attribute in the base class of the hierarchy (the ancestor class). The inherited child classes can't have their own Id attribute.

 

For composite id's, specify as many Id attributes as you need to build the composite identifier.

 

Constructor

constructor Create(AMemberName: string; AGenerator: TIdGenerator);

 

Parameters

 

AMemberName

Contains the name of field or property that identifies the object

AGenerator

Indicates how the Id value will be generated. Valid values are (prefixed by TIdGenerator):

 

None

Id value will not be automatically generated. Your application must assign a value to it and be sure it's unique

 

IdentityOrSequence

Aurelius will ask the database to generate a new Id. If the database supports sequences and a sequence is defined, then Aurelius will use the sequence to generate the value. Otherwise, it will use identity (auto-numerated) fields. If no sequence is defined and database doesn't support identity fields, an exception will be raised. The name of the sequence to be created and used by Aurelius can be defined using the Sequence attribute. The type of the property that identifies the entity should be integer.

 

Guid

Aurelius will generate a GUID (Globally Unique Identifier) value as the entity identifier. The type of the property that identifies the entity should be TGuid or string.

 

Uuid38

Aurelius will generate a 38-length UUID (Universally Unique Identifier) value as the entity identifier. An UUID is just a string representation of a GUID value, with the format "{550e8400-e29b-41d4-a716-446655440000}" (with hifens and curly brackets). The type of the property that identifies the entity should be string (with a minimum length of 38 characters)

 

Uuid36

Aurelius will generate a 36-length UUID (Universally Unique Identifier) value as the entity identifier. An UUID is just a string representation of a GUID value, with the format "550e8400-e29b-41d4-a716-446655440000" (with hifens but no curly brackets). The type of the property that identifies the entity should be string (with a minimum length of 36 characters)

 

Uuid32

Aurelius will generate a 32-length UUID (Universally Unique Identifier) value as the entity identifier. An UUID is just a string representation of a GUID value, with the format "550e8400e29b41d4a716446655440000" (no hifens and no curly brackets). The type of the property that identifies the entity should be string (with a minimum length of 32 characters)

 

SmartGuid

Aurelius will generate a sequential GUID (Globally Unique Identifier) value optimized for the database being used. The generated sequential GUID will minimize clustered index fragmentation, which is an usual problem when using regular GUID's, causing performance loss. Aurelius will choose the best algorithm to generate the GUID sequence depending on the database being used. For most of them, the GUID will be sequential in its string format, which is optimum for most databases and also when you use string properties. For Microsoft SQL Server, for example, it will choose a different algorithm (sequential in the last bytes) which is best given the way SQL Server sorts GUID's internally. In general you should use SmartGuid generator instead of Guid since both achieve the same results but SmartGuid performs better.

 

For composite id's this value is ignored and None is used.

 



 

Usage

 

[Id('FId', TIdGenerator.IdentityOrSequence)]
TCustomer = class(TObject)
private
  [Column('CUSTOMER_ID')]
  FId: integer;