Base entity class

Hello,


I am wondering if it is possible to define a set of common properties in an ancestor class for my entities (the way EntityFramework lets you work):

I tried the following code but the ID column isn't generated (or used):

  TBase = class
  private
    FID: Integer;
  public
    [Id]
    property ID: Integer read FID write FID;
  end;

  [Entity]
  [Automapping]
  TData = class(TBase)
  private
    FName: String;
  public
    property Name: String read FName write FName;
  end;

I will need to map a large number of entities from a legacy application where data is stored in fixed-sized records. All these entities shared a common record header and I would like to avoid having to copy the same fields in all entities.



Hello Stephane,

You can have such fields in ancestor class, but you will have to map them in descendant class:

TBase = class
  private
    FID: Integer;
  public
    property ID: Integer read FID write FID;
  end;

  [Entity]
  [Id('Id', TIdGenerator.IdentityOrSequence)]
  TData = class(TBase)
  private
    FName: String;
  public
    [Column('Id')]
    property Id;
  end;