entity with dto

in an entity I cannot have a DTO-type association? because it gives the following error: EEntityTypeClassNotMapped: Cannot create entity type class TTotaisItens. Class is not mapped

[Entity]
[Table('mat_movimento')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Sequence('seq_mat_movimento')]
[Inheritance(TInheritanceStrategy.JoinedTables)]
TMovimentoMat = class(TModeloBsc)
private
[Column('id', [TColumnProp.Required])]
FId: int64;
[Column('entrada_saida', [TColumnProp.Required])]
FEntradaSaida: integer;
[Transient]
FTotaisItens: TTotaisItens;

[JsonInclude(TInclusionMode.NonDefault)]
TTotaisItens = class
Mercadoria: currency;
Itens: currency;
Pecas: currency;
Valor: currency;
end;

Have you defined

TTotaisItens = class;

before TMovimentoMat declaration?

Yes

Could you paste or check the original source code section where you have declared TMovimentoMat & TTotaisItens ?
No errors here using this structure, Neither declaring outside of the main entity, nor inside of it as a nested type.

You can have any properties in your entity class, as long as they are not mapped to the database. You can map a non-entity class to the database.

I want the FTotaisItens property to go to json. when I put [XDataProperty] there is an error in the application initialization

What error?

EEntityTypeClassNotMapped: Cannot create entity type class TTotaisItens. Class is not mapped

function TXDataModelBuilder.DefineEntityType(AClass: TClass): TXDataEntityType;

Indeed, XDataProperty only works for primitive types, not object types.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.