ELIStError on attach method
Posted: Tue 17 Mar 2020 20:47
When I run this code, I get "Elisterror : The list don't allow duplicates"
When the first object of type TChiamata is attached the primary key remain the same and this create the error when attach the second object (tchiamata)
I know that primarykey is incremented into database layer. Why this happens ? Doesn't attach method increment the key?
Any suggestions?
var
p : TContatto;
c,c1 : TChiamata;
begin
p := tcontatto.Create;
p.Cognome := 'Giorgio';
p.Nome := 'Bartolo';
p.Indirizzo := 'V.le J.F. Kennedy';
p.Numero_Civico := '87';
p.CAP := '70124';
p.Paese := 'Italia';
p.Numero := '3936620642';
c := TChiamata.Create;
c.Data := Now;
c.Ora := Time;
c.Durata := 10.2;
c.NumeroChiamato := '0805610257';
c1 := TChiamata.Create;
c1.Data := Now;
c1.Ora := Time;
c1.Durata := 10.2;
c1.NumeroChiamato := '0805610257';
mdati.EntityContext1.Attach(p);
mdati.EntityContext1.Attach(c);
mdati.EntityContext1.Attach(c1); // here the error is arised
p.Chiamate.Add(c);
p.Chiamate.Add(c1);
MDati.EntityContext1.Save(p);
MDati.EntityContext1.Save(c);
MDati.EntityContext1.Save(c1);
When the first object of type TChiamata is attached the primary key remain the same and this create the error when attach the second object (tchiamata)
I know that primarykey is incremented into database layer. Why this happens ? Doesn't attach method increment the key?
Any suggestions?
var
p : TContatto;
c,c1 : TChiamata;
begin
p := tcontatto.Create;
p.Cognome := 'Giorgio';
p.Nome := 'Bartolo';
p.Indirizzo := 'V.le J.F. Kennedy';
p.Numero_Civico := '87';
p.CAP := '70124';
p.Paese := 'Italia';
p.Numero := '3936620642';
c := TChiamata.Create;
c.Data := Now;
c.Ora := Time;
c.Durata := 10.2;
c.NumeroChiamato := '0805610257';
c1 := TChiamata.Create;
c1.Data := Now;
c1.Ora := Time;
c1.Durata := 10.2;
c1.NumeroChiamato := '0805610257';
mdati.EntityContext1.Attach(p);
mdati.EntityContext1.Attach(c);
mdati.EntityContext1.Attach(c1); // here the error is arised
p.Chiamate.Add(c);
p.Chiamate.Add(c1);
MDati.EntityContext1.Save(p);
MDati.EntityContext1.Save(c);
MDati.EntityContext1.Save(c1);