I have a master/Detail relationship mapped as follows:
[Entity]
[Table('TBLREZEPT')]
[Id('FREZEPTID', TIdGenerator.None)]
TTBLREZEPT = class
private
[Column('REZEPTID', [TColumnProp.Required, TColumnProp.NoUpdate])]
FREZEPTID: Integer;
[ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll , 'FREZEPTID')]
[Table('TBLREZEPT')]
[Id('FREZEPTID', TIdGenerator.None)]
TTBLREZEPT = class
private
[Column('REZEPTID', [TColumnProp.Required, TColumnProp.NoUpdate])]
FREZEPTID: Integer;
[ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll , 'FREZEPTID')]
FTBLREZEPTZUTATList: Proxy<TList<TTBLREZEPTZUTAT>>;
public
public
and
[Entity]
[Table('TBLREZEPTZUTAT')]
[Id('FREZEPTID', TIdGenerator.None)]
[Id('FREZEPTPOSID', TIdGenerator.None)]
TTBLREZEPTZUTAT = class
private
[Column('REZEPTPOSID', [TColumnProp.Required, TColumnProp.NoUpdate])]
FREZEPTPOSID: Integer;
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('REZEPTID', [TColumnProp.Required], 'REZEPTID')]
FREZEPTID: Proxy<TTBLREZEPT>;
[Table('TBLREZEPTZUTAT')]
[Id('FREZEPTID', TIdGenerator.None)]
[Id('FREZEPTPOSID', TIdGenerator.None)]
TTBLREZEPTZUTAT = class
private
[Column('REZEPTPOSID', [TColumnProp.Required, TColumnProp.NoUpdate])]
FREZEPTPOSID: Integer;
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('REZEPTID', [TColumnProp.Required], 'REZEPTID')]
FREZEPTID: Proxy<TTBLREZEPT>;
This is a legacy DB, so I provide the IDs myself Prior to inserting the records.
Adding is no Problem:
SAVE the REZEPT
add and save each ZUTAT:
Zutat := TTblrezeptzutat.Create;
Zutat.REZEPTPOSID := uc.GetNextID('tblrezeptzutat.rezeptposid');
mgrManager.Save(Zutat);
Rezept.TBLREZEPTZUTATList.Add(Zutat);
Zutat.REZEPTPOSID := uc.GetNextID('tblrezeptzutat.rezeptposid');
mgrManager.Save(Zutat);
Rezept.TBLREZEPTZUTATList.Add(Zutat);
However, when I want to update the REZEPT, i first want to delete all ZUTAT:
for Zutat in Rezept.TBLREZEPTZUTATList do begin
mgrManager.Remove(Zutat);
end;
mgrManager.Remove(Zutat);
end;
The DELETE Statements are created and executed.
However, adding fails:
Zutat := TTblrezeptzutat.Create;
Zutat.REZEPTPOSID := uc.GetNextID('tblrezeptzutat.rezeptposid');
mgrManager.Save(Zutat); < --------------------- ERROR
Zutat.REZEPTPOSID := uc.GetNextID('tblrezeptzutat.rezeptposid');
mgrManager.Save(Zutat); < --------------------- ERROR
Im Projekt RezeptSchnittstelle.exe ist eine Exception der Klasse EMappingNotFound mit der Meldung 'Cannot find mapping [Id] on class "nil".' aufgetreten.
This is weird, because without the removing, this works ok.
Any idea?