Skip to main content

AutomappingAttribute Class

Enables simplified table and column mapping for an entity class.

Declaration

AutomappingAttribute = class(
    TCustomAttribute
)

Remarks

Simplified table and column mapping causes the ExpressEntityMapping Framework to infer mapping information from the class’s name and fields in the following manner:

  • The class name is considered the table name. The ‘T’ prefix is automatically removed.

  • A primary key column called Id is created automatically if the class includes an Integer or Int64 field called ‘FId’ or ‘fId’. The column is an auto-incremented identity if this field is associated with a read-only Id property. Once the Id primary key column is created, all other KeyAttributes in this class are ignored.

  • A column is created for each ordinal, nullable, collection, or generic collection field, or a field that references an entity class. Fields marked with the NonPersistentAttribute are ignored. The field’s name is considered the column name. The prefix (‘F’ or ‘f’) is automatically removed. The column type and size are determined based on the field’s data type and are specific to the database within which a session component creates the entity model’s schema. The string column size limit is 100 characters. Use the TdxSQLConnectionProvider.DefaultStringSize class variable to adjust it.

You can use the TableAttribute, ColumnAttribute, DBTypeAttribute, SizeAttribute, and other attributes to override the default mapping. Attributes applied to properties are ignored.

The following code example uses the AutomappingAttribute to create the schema that is identical to the schema created by the class declaration described in this section. Note that the NonPersistentAttribute excludes the FQuickNote field (and a corresponding column) from the schema.

uses
  ..., dxEMF.Core, dxEMF.Attributes;
type
  [Entity]
  [Automapping]
  TPerson = class
  strict private
    FId: Integer;
    FAge: Integer;
    FName: string;
    [NonPersistent]
    FQuickNote: string;
  public
    property Id: Integer read FId;
  end;

Inheritance

TObject
TCustomAttribute
AutomappingAttribute
See Also