Print Page | Close Window

parent child insertion record with (Oracle)

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=2121
Printed Date: 10-Jun-2026 at 5:28pm


Topic: parent child insertion record with (Oracle)
Posted By: Molinari
Subject: parent child insertion record with (Oracle)
Date Posted: 03-Sep-2010 at 7:48am
Hi There

I catch up with other Database Problem.
I am working with parent and child and below code works fine with MS SQL SERVER
But Throwing Exception in Oracle

My aim is to Insert one record after another record.Its works fine when I insert single record
but if I try to insert another one getting error.

            var mgr = new Entities();
            for (int i = 0; i < 10; i++)
            {
               ITEMVENDA c = new ITEMVENDA() { NOME = "DEV " + i,   VALORUNIT = 11, FK_VENDAID = 43 };
               mgr.AddEntity(c);
            }
            mgr.SaveChangesAsync(op =>
            {
               if (op.IsCompleted)
                    MessageBox.Show("Sucess");
               else
                    MessageBox.Show(op.Error.Message);
            });

Excepyion:-   An entity with this key: ITEMVENDA: 0 already exists in this EntityManage



Replies:
Posted By: kimj
Date Posted: 03-Sep-2010 at 9:18am
Can you check the ITEMVENDA ID assignment after adding each entity - is the ID always 0? If so, then it sounds like the ID might not be recognized as an "auto-increment" or store-generated ID. 
 
In the CSDL section of your EDMX, check that the ID property for ITEMVENDA indicates it is store generated.  For example, it should look something like this:
          <Property Name="ITEMVENDA_ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
 
If the StoreGeneratedPattern is not in the entity definition in the CSDL, but is defined for the entity in the SSDL, then this is a problem with the EF Oracle provider.  Which provider are you using?


Posted By: Molinari
Date Posted: 03-Sep-2010 at 10:51am
Hi thanks for reply
My ID not always storing value 0

I am using Devart provider v5.60 for oracle.

Why I have problem with oracle and its working good with MS SQL Server
I am facing other problem of parent child insertion in oracle.

Is DevForce much not confirmtable with Oracle?

I testing and occurred this error :

A depended property in a ReferentialConstraint is mapped to a store-generated column. Column:FK_VENDAID!!!



Posted By: kimj
Date Posted: 03-Sep-2010 at 11:10am
DevForce is agnostic regarding the actual database and provider used, since all database access is done through the Entity Framework.  It's likely that the problem is with the provider, so please check both the CSDL and SSDL definitions of this entity in the EDMX to see that the StoreGeneratedPattern is set correctly on the ID property.  You can post or upload your EDMX here if you have any questions.


Posted By: Molinari
Date Posted: 03-Sep-2010 at 11:24am
hey i am uploding my EDMX

could you see the problem. please.

uploads/911/edmx.txt - edmx.txt




Thanks by attention


Posted By: kimj
Date Posted: 03-Sep-2010 at 12:14pm
Your entities are not defined correctly.
 
VENDA.VENDAID should have the StoreGeneratedPattern attribute in both SSDL and CSDL.  This is the parent entity, and its ID is assigned by the database when a record is inserted.
 
ITEMVENDA.FK_VENDAID should not have the StoreGeneratedPattern attribute in either SSDL or CSDL.  This is a foreign key field, and the value will come via your code and DevForce, when you do something like anItemVenda.Venda = aVenda.
 
To make these changes you will likely need to manually edit the XML in the EDMX.


Posted By: Molinari
Date Posted: 03-Sep-2010 at 1:24pm
Problem Solved.

Problem was in EDMX.

Thanks very much.....


Posted By: Molinari
Date Posted: 03-Sep-2010 at 1:39pm
I would like to ask one more thing...

Rather every time update a EDMX manually. Do you know any way that we can convert that decimal value to int. Automatically.

because the DB has more than 200 table.

you can not keep doing manually


Thanks...


Posted By: kimj
Date Posted: 03-Sep-2010 at 3:24pm
In theory choosing the right data type for properties in the CSDL is the responsibility of the Oracle provider, so check with Devart to see if this is a known problem or has a workaround.


Posted By: Molinari
Date Posted: 06-Sep-2010 at 4:11am
OK.

Thanks very much



Print Page | Close Window