I am trying to get the "id" property from my entity using Dynamic Properties. However it is empty. I have tried with other field "nome" and it is empty either.
The entity contains value.
I have added the property required:
property Props: TDynamicProperties read FProps;
On my base class, that is not tagged as [Entity], all my entity classes inherits from it.
I am not sure that is allowed. If the property itself needs to be in the class that is the table, can I keep the FProps on my base class?
I want to have a way to interact with the data in a generic way, using my base class only. For that I have added another property
property Value[const PropName: string]: Variant read GetVariantProp write SetVariantProp; default;
That is default for the class to read the TDynamicProperties and be used like this:
EntityItem['nome']
for each of my entity classes I have a registering initialization:
NaharEntityFactory.RegisterEntity(TEntityItem.EntityName,
function(AContext: INaharContext): TNaharEntity
begin
result := TEntityItem.Create;
result.Context := AContext;
end,
function(AMappingSetup: TMappingSetup): Boolean
begin
AMappingSetup.MappedClasses.RegisterClass(TEntityItem);
AMappingSetup.DynamicProps[TEntityItem];
result := true;
end);
The first anonymous function is to create the entity, the second is called when preparing the map setup and then the TMappingExplorer for each database. I used this way to give a chance to add new fields to the entity on initialization.
I am trying to clone the entity and I see that CopyFieldValues is working.
Now I need to extract the ID from my source entity and I am trying to do that using Dynamic Properties, but it is empty.