Hello,
im am using Visual studio 2019, .NET Core 3.1 and devart.data.oracle.efcore (9.11.980).
I get the Error ORA-02291, when i am trying to save values in two Tables with dependencies.
For Example:
The Properties ID from TABLEA and TABLEB are generated in the Oracle-Database.
TABLEB.ID_TABLEA is linked to TABLEA.ID
using (Data.Model context = new Data.Model())
{
TABLEA newRowA = new TABLEA();
newRowA.TEXT = "hy";
context.TABLEA.Add(newRowA);
TABLEB newRowB = new TABLEB();
newRowB.ID_TABLEA = newRowA.ID;
context.TABLEB.Add(newRowB);
context.SaveChanges() > ERROR 02291
}
The ID-Properties of both Tables ar set to Value Generated "OnAdd".
When i perform context.SaveChanges() after adding TABLEA the ID is generated and i can save TABLEB.
But when one insert fails, then nothing should be in the Database.
That is not an Option in this case.
Thanks for your help.
Roman
ORA 02291 integrity constraint violated-parent key not found
Re: ORA 02291 integrity constraint violated-parent key not found
IDs do not exist in .NET objects until you call SaveChanges(). You should use navigation property instead of assigning non-existing ID:
newRowB.ID_TABLEA = newRowA.ID;
->
newRowB.ToTableANavigationProperty = newRowA;
JIC: you can use transactions, or wrap your code with the global transaction.
Re: ORA 02291 integrity constraint violated-parent key not found
Hy,
I began using navigation properties as you suggested. That works fine.
Thank you very much for your help.
Best regards Roman
I began using navigation properties as you suggested. That works fine.
Thank you very much for your help.
Best regards Roman