Hi Wagner,
I am in trouble with this code, I am posting here what I have for one specific table:
type
TEntityDominio = class;
TNaharEntity = class
private
FDominio: TEntityDominio;
protected
procedure SetDominio(Value: TEntityDominio);
function GetDominio: TEntityDominio;
public
constructor Create; virtual;
end;
[Entity]
[Table('DOMINIO')]
[Id('ID', TIdGenerator.None)]
TEntityDominio = class(TNaharEntity)
private
FId: TGuid;
FNome: string;
private
procedure SetNome(const Value: string);
public
constructor Create; override;
[Column('ID', [TColumnProp.Unique, TColumnProp.NoUpdate])]
property Id: TGuid read FId write FId;
[Column('NOME', [TColumnProp.Required, TColumnProp.Unique], 20)]
property Nome: string read FNome write SetNome;
end;
implementation
{ TNaharEntity }
constructor TNaharEntity.Create;
begin
end;
function TNaharEntity.GetDominio: TEntityDominio;
begin
result := FDominio;
end;
procedure TNaharEntity.SetDominio(Value: TEntityDominio);
begin
FDominio := Value;
end;
{ TEntityDominio }
constructor TEntityDominio.Create;
begin
inherited;
FId := GUID_NAHAR_DOMAIN_DEFAULT;
end;
procedure TEntityDominio.SetNome(const Value: string);
begin
FNome := Value;
end;
Problems that I have with this code:
1) It is raising a EUnexpectedFieldType: Nahar.Entity.TEntityDominio when creating the database
2) I have added the base class (that is not a table) TNaharEntity because I want to declare on the Constructor (that is empty right now) the DEFAUL TNaharDominio.
I have explained this in a previous post, however for the sake of clarity: Dominio is a overall filter for almost all the tables. If I am working with the company 1 for example, everything needs to be selected based on the DOMINIO that was defined for company 1.
As you can see is a simple table. And you can see that the FDominio is declared on the base class. So all the other tablets that are decendant of this class will only define the property with the tag Column Dominio. The set and get are already defined and the default value would be pre defines already.
The fact is that Aurelius in some situations create the Class on its own, then I need to be sure that Dominio is always correct (I have a singleton that keeps it for me). The record can be written wrong in many ways, but never with the wrong dominio.
What should I do? Load a TEntityDominio and keep it in memory to make the attribution
FDominio := FLoadedEntityDominio every time the base class is created?