Skip to main content

GeneratorAttribute Class

Specifies how an auto-incremented primary key generates its values.

Declaration

GeneratorAttribute = class(
    TCustomAttribute
)

Remarks

Automatic key value generation is supported for Integer, Int64, and TGUID type fields/properties. TGUID key values are always generated on the client side, while Integer and Int64 key values are generated by a data store, on its side. Depending on the data store type, automatic key generation is implemented using identity/autonumber/auto-increment columns or sequences. If a data store doesn’t support any of these, the ExpressEntityMapping Framework generates key values.

Pass the generation type (a TdxGeneratorType enumeration value) as a parameter to the GeneratorAttribute parameter to specify how key values are generated. To use a specific sequence to generate key values, pass its name as the second parameter. Refer to the TdxGeneratorType type description to learn about the available generation options.

The following code is the KeyAttribute example extended with automatic key value generation for the Id primary key column.

uses
  ..., dxEMF.Core, dxEMF.Attributes, dxEMF.Types;
type
  [Entity]
  TPerson = class
  strict private
    [Column, Key, Generator(TdxGeneratorType.Identity)]
    FId: Integer;
    [Column]
    FName: string;
  public
    // ...
  end;

The following code shows how to generate key values using the persons_seq sequence.

[Column, Key, TdxGeneratorType.Sequence, 'persons_seq')]
    FId: Integer;

Inheritance

TObject
TCustomAttribute
GeneratorAttribute
See Also