Print Page | Close Window

Parent child Insertion problem (0racle)

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2092
Printed Date: 10-Jun-2026 at 5:28pm


Topic: Parent child Insertion problem (0racle)
Posted By: bala
Subject: Parent child Insertion problem (0racle)
Date Posted: 25-Aug-2010 at 6:29am
Hi There
 
I have one two table with parent and child relation. I want to insert record in child table
 
I am using following code for inserting..
 
            ITEMVENDA novoItem = new ITEMVENDA();
            novoItem.NOME = txtNome.Text;
            novoItem.VALORUNIT = Convert.ToDecimal(txtValorUnit.Text);
          
          VENDA novo = new VENDA();
            novo.TIPOPAGAMENTO = txtTipoPgto.Text.ToUpper();
            novo.VALORTOTAL = Convert.ToDecimal(txtValorTotal.Text);
            novo.ITEMVENDA.Add(novoItem);

            _entityManager.AddEntity(novo);
            _entityManager.SaveChangesAsync(args =>
            {
                if (args.IsCompleted)
                    activity1.IsActive = false;
                else
                    MessageBox.Show(args.Error.Message);
            });

I have this error while saving..
 
ORA-02291 Intergrity constraint (Client_Novo.FK_ItemVenda_Venda)
Violeted - Parent Key not found
 
Any Help would be appriciated..
 
Thanks
 



Replies:
Posted By: BillG
Date Posted: 25-Aug-2010 at 12:42pm
Has the parent record been inserted yet? Its seems that it can't find a parent record with that key.
 
Bill
 


Posted By: DenisK
Date Posted: 25-Aug-2010 at 2:29pm
Bala;

Searching on Google gives me this

ORA-02291:

integrity constraint (string.string) violated - parent key not found
Cause:A foreign key value has no matching primary key value.
Action:Delete the foreign key or add a matching primary key.

You might want to take a look at your novoItem object and see if its foreign key has been linked to the primary key of novo. 


Posted By: bala
Date Posted: 26-Aug-2010 at 4:15am
Thanks for answer..
I undestand the error and I know how it comes. But I like to know How the error generating from
my code. Because When I inserting manually it not showing any such error.

But when we try to insert from UI code this error population.

Is there any problem in my Code ?

If I am right it is not necerssary to bring ID of the parent to insert in Child. Navigation does automatically
it search ID for parent.

HOw can I acheive this?

If have with example that could be great help..

Thanks


Posted By: DenisK
Date Posted: 26-Aug-2010 at 1:38pm
Bala;

I'm going to need more information from you. Could you provide me with the following?

1. Your DevForce version

2. How your VENDA and ITEMVENDA tables are associated on your database.

Thanks,


Posted By: bala
Date Posted: 26-Aug-2010 at 2:02pm

Thanks for reply

Version is DevForce2010 v6.0.4.0

Yes, have realation one to many

VENDA 1 ============* ITEMVENDA


Thanks


Posted By: DenisK
Date Posted: 26-Aug-2010 at 3:45pm
Bala;

I did a similar test insertion using the NorthwindIB database with the same parent child relation and it worked. So I'm guessing that it has something to do with your Entity Data Model. Could you upload your edmx file to the forum?

Thanks. 


Posted By: bala
Date Posted: 27-Aug-2010 at 1:50pm
hey i I uploaded Images..
Could you see and tell me..

Where is problem..


Have a nice weekend..



Posted By: bala
Date Posted: 27-Aug-2010 at 1:58pm
uploads/896/imagem11.rar - uploads/896/imagem11.rar


Posted By: bala
Date Posted: 27-Aug-2010 at 1:59pm
uploads/896/imagem12.rar - uploads/896/imagem12.rar


Posted By: DenisK
Date Posted: 30-Aug-2010 at 12:14pm
Bala;

I duplicated your database using the screenshots that you had sent me and I wrote the exact same logic (see below). I did not get any error. I've attached my edmx file. Maybe you can see what my edmx file is like and compare it to yours. Hopefully it will help.

     var mgr = new ModelTestEntityManager();

      ITEMVENDA novoItem = new ITEMVENDA();
      novoItem.NOME = "some NOME text";
      novoItem.VALORUNIT = 10;

      VENDA novo = new VENDA();
      novo.TIPOPAGAMENTO = "some TIPO text";
      novo.VALORTOTAL = 10;
      novo.ITEMVENDAs.Add(novoItem);

      mgr.AddEntity(novo);
      mgr.SaveChangesAsync(args => {
        if (args.CompletedSuccessfully) {
          Output = "Completed successfully";
        } else {
          Output = "Save operation has the following errors: " + args.Error.Message;
        }
      });

uploads/912/ModelTestModelEdmx.zip - uploads/912/ModelTestModelEdmx.zip


Posted By: bala
Date Posted: 30-Aug-2010 at 12:52pm
Hi
I copy your code but few keywords does not exits.
   if (args.CompletedSuccessfully) {
i do not have completedSucessfully..

 Which version are you using?
And your zip file also not opening..

Could you post again?

Thanks for replying..





Posted By: DenisK
Date Posted: 30-Aug-2010 at 4:25pm
Bala;

Please try the link again and use this statement instead.

if (!args.HasError)


Posted By: bala
Date Posted: 31-Aug-2010 at 6:51am
Hi Denisk..

Finally I made database in SQL server and got sucess.

But still I need to solve problem with Oracle.I am using oracle database for my project.

Thanks for you vital help. Can you try this stuff in oracle If you have.


Thanks a Lot






Posted By: DenisK
Date Posted: 31-Aug-2010 at 11:52am
Hi Bala;

It does sound curious as to why it works in Microsoft SQL server but not in Oracle. Let me test it out with Oracle and let you know.


Posted By: bala
Date Posted: 03-Sep-2010 at 5:19am
Hi Denisk
 
Did you check solution with Oracle. This is I really need to work with oracle.
Please check and let me know..
 
Thanks for helping...


Posted By: Molinari
Date Posted: 03-Sep-2010 at 1:26pm
Hey Bala, look this link:

http://www.ideablade.com/forum/forum_posts.asp?TID=2121&PID=8353#8353

this will solve the problem.


Posted By: bala
Date Posted: 03-Sep-2010 at 1:42pm
Yeah very much working for me

Thanks you solved my big problem

:)



Print Page | Close Window