Hello!
We have a situation where we wish to load, in a lump, three tables that are related to each other (AmbitiTerritoriali, AmbitiTerritoriali_Comuni, Comuni). As you can guess the two ends of the relationship are AmbitiTerritoriali and Comuni with the middle one being a many-to-many (ie one Comuni can be linked to more than one AmbitiTerritoriali and viceversa).
We need to load it all in a lump because loading Comuni one by one simply doesn't work for us from a performance standpoint.
To this end, I wish to adjust the model and I am thinking of using a ManyValuedAssociation, like so:
[Entity]
[Table('CMTAMBITITERRITORIALI')]
TCMTAMBITITERRITORIALI = class(TIDNullableDescription100WithLog)
private
[Column('CODICE', [TColumnProp.Required], 30)]
FCODICE: string;
[Column('ATTIVA', [TColumnProp.Required], 1)]
FATTIVA: string;
public
property CODICE: string read FCODICE write FCODICE;
property ATTIVA: string read FATTIVA write FATTIVA;
end;
[Entity]
[Table('CMTAMBITITERRITORIALI_COMUNI')]
TCMTAMBITITERRITORIALI_COMUNI = class(TIdLogModelBase)
private
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ID_CMTAMBITITERRITORIALI', [TColumnProp.Required], 'ID')]
FID_CMTAMBITITERRITORIALI: Proxy<TCMTAMBITITERRITORIALI>;
[ManyValuedAssociation([], CascadeTypeAll - [TCascadeType.Remove])]
// [JoinColumn('ID_CMTCOMUNI', [TColumnProp.Required], 'ID')]
FID_CMTCOMUNI: TList<TCMTCOMUNI>;
function GetID_CMTAMBITITERRITORIALI: TCMTAMBITITERRITORIALI;
procedure SetID_CMTAMBITITERRITORIALI(const Value: TCMTAMBITITERRITORIALI);
public
property ID_CMTAMBITITERRITORIALI: TCMTAMBITITERRITORIALI read GetID_CMTAMBITITERRITORIALI write SetID_CMTAMBITITERRITORIALI;
property ID_CMTCOMUNI: TList<TCMTCOMUNI> read FID_CMTCOMUNI write FID_CMTCOMUNI;
end;
[Entity]
[Table('CMTCOMUNI')]
TCMTCOMUNI = class( TIDDescription250WithLog )
private
[Column('CODICE_ISTAT', [TColumnProp.Required], 8)]
FCODICE_ISTAT: string;
[Column('ID_SYTNAZIONI', [])]
FID_SYTNAZIONI: Nullable<Integer>;
[Column('ATTIVA', [], 1)]
FATTIVA: Nullable<string>;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ID_CMTPROVINCE', [], 'ID')]
FID_CMTPROVINCE: Proxy<TCMTPROVINCE>;
[Column('RADON', [], 1)]
FRADON: Nullable<string>;
function GetID_CMTPROVINCE: TCMTPROVINCE;
procedure SetID_CMTPROVINCE(const Value: TCMTPROVINCE);
public
property CODICE_ISTAT: string read FCODICE_ISTAT write FCODICE_ISTAT;
property ID_SYTNAZIONI: Nullable<Integer> read FID_SYTNAZIONI write FID_SYTNAZIONI;
property ATTIVA: Nullable<string> read FATTIVA write FATTIVA;
property ID_CMTPROVINCE: TCMTPROVINCE read GetID_CMTPROVINCE write SetID_CMTPROVINCE;
property RADON: Nullable<string> read FRADON write FRADON;
end;
Unfortunately, when I try this model all I get is
ThreadId=7360
ProcessId=9
ThreadName="Main Thread"
ExceptionMessage="Property "D_CMTAMBITITERRITORIALI" not found on class "TCMTAMBITITERRITORIALI_COMUNI"."
ExceptionName="EPropertyNotFound"
ExceptionDisplayName="EPropertyNotFound"
ExceptionAddress=76DB5AA2
FileName=<not available>
LineNumber=<not available>
ExceptionObject=08387278
Classes=[EPropertyNotFound,EAureliusException,Exception,TObject]
Which to my mind makes zero sense.
Please find the rest of the inheritance here:
IDataLog = interface
['{BC565DE6-E578-482A-B631-CBC0111918D3}']
function GetUserIns: string;
function GetDataIns: Int64;
procedure SetUserIns( const Value: string );
procedure SetDataIns( const Value: Int64 );
function GetUserUpd: string;
function GetDataUpd: Int64;
procedure SetUserUpd( const Value: string );
procedure SetDataUpd( const Value: Int64 );
property UserIns: string read GetUserIns write SetUserIns;
property DataIns: Int64 read GetDataIns write SetDataIns;
property UserUpd: string read GetUserUpd write SetUserUpd;
property DataUpd: Int64 read GetDataUpd write SetDataUpd;
end;
[AbstractEntity]
TModelBase = class( TBFivePersistentObject )
end;
[AbstractEntity]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TIDModelBase = class( TModelBase )
strict private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FID: Integer;
procedure SetID(const Value: Integer);
public
property ID: Integer read FID write SetID;
end;
[AbstractEntity]
TIDLogModelBase = class( TIDModelBase, IDataLog )
strict private
[Column('USER_INS', [], 50)]
FUSER_INS: Nullable<string>;
[Column('DATA_INS', [])]
FDATA_INS: Nullable<TDateTime>;
[Column('USER_UPD', [], 50)]
FUSER_UPD: Nullable<string>;
[Column('DATA_UPD', [])]
FDATA_UPD: Nullable<TDateTime>;
FUnixConvert: IUnixDateTimeConvert;
FStringConvert: INullableString;
strict protected
function GetUserIns: string;
function GetDataIns: Int64;
procedure SetUserIns( const Value: string );
procedure SetDataIns( const Value: Int64 );
function GetUserUpd: string;
function GetDataUpd: Int64;
procedure SetUserUpd( const Value: string );
procedure SetDataUpd( const Value: Int64 );
public
constructor Create; override;
property USER_INS: Nullable<string> read FUSER_INS write FUSER_INS;
property DATA_INS: Nullable<TDateTime> read FDATA_INS write FDATA_INS;
property USER_UPD: Nullable<string> read FUSER_UPD write FUSER_UPD;
property DATA_UPD: Nullable<TDateTime> read FDATA_UPD write FDATA_UPD;
end;
[AbstractEntity]
TIDDescription250WithLog = class( TIDLogModelBase )
strict private
[Column('DESCRIZIONE', [TColumnProp.Required], 250)]
FDescrizione: string;
procedure SetDescription(const Value: string);
public
property Descrizione: string read FDescrizione write SetDescription;
end;
Can you please advice where I am going wrong with this?
Thank you!