Skip to main content

Entity Class Registration

  • 2 minutes to read

The ExpressEntityMapping Framework provides the following options to register entity model classes for use in code and specify mapping information for them and their members:

  • Built-in attributes (Delphi only). The attributes allow you to provide mapping details, establish relationships between entity classes, define entity inheritance, and other settings in class declarations. A class marked with the EntityAttribute is automatically registered in the entity model at runtime. To enable the built-in attributes in your project, add the dxEMF.Attributes unit to the ‘uses’ clause. This option applies to the Delphi code only, because C++Builder does not support Delphi attributes.

  • The entity manager (Delphi and C++Builder). This option means that you declare each entity class without attributes and provide its mapping information in the initialization section using the entity manager’s RegisterEntity function and a sequence of calls to functions made from another call’s result. The functions include RegisterField, RegisterProperty, and equivalents of the built-in attributes (they bear the same names and accept the same parameters). Call the global EntityManager function declared in the dxEMF.Metadata unit to access the entity manager and its API.

Refer to this section for a code example on how to declare a simple TPerson entity class mapped to the Person table using the Entity, Table, Column, Key, and Generator built-in attributes. The following code example uses the entity manager to register this entity class.

uses
  ..., dxEMF.Core, dxEMF.Types, dxEMF.Metadata;
type
  TPerson = class
  strict private
    FId: Integer;
    FAge: Integer;
    FName: string;
  public
    property Id: Integer read FId;
    property Age: Integer read FAge write FAge;
    property Name: string read FName write FName;
  end;
implementation
initialization
  EntityManager.RegisterEntity(TPerson).Table('Person').
    RegisterField('FId').Generator(TdxGeneratorType.Identity).Key.
    RegisterProperty('Age').
    RegisterProperty('Name');

In the Entity Model Designer, you can select the method used to register entity classes in generated unit files using the entity model’s CodeGenerationEntityRegistrationType property.