Parent - Child insert with .Net Entity Framework

Parent - Child insert with .Net Entity Framework

Postby intiwilly » Fri 08 Jan 2010 08:56

Hi,

I'm using dotConnect Oracle 5.35.62 trial version. I want to ask how to insert parent child association in one transaction.
Maybe similiar like this in SQL Server version http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/8f5ef62c-b5a5-4b61-af84-08ebc480ee8a/

I've tried this following code :

Code: Select all
            Master ap = new Master();
            Detail ad = new Detail();
            ap.Name = "Test Data";
            ad.Visited = "US";

            ap.Detail.Add(ad);

            db.AddToMaster(ap);
            db.SaveChanges();


The record successfully insert to both table in database but the reference id (MasterId Column) in Detail table always refer to 0.

I've use trigger and sequence to produce auto increment number both in Master table and Detail table and it work fine if i do this with sql insert query.

Is there any idea how to do this with valid reference id?

Thanks,
intiwilly
 
Posts: 3
Joined: Fri 08 Jan 2010 08:37

Postby AndreyR » Tue 12 Jan 2010 10:00

I have just tried the same code and succeeded. Please make sure that you have set the StoreGeneratedPattern attribute
for the autoincremented columns to Identity, this may be the reason.
We don't have an opportunity to set this attribute automatically in Oracle.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby intiwilly » Thu 21 Jan 2010 09:24

AndreyR wrote:I have just tried the same code and succeeded. Please make sure that you have set the StoreGeneratedPattern attribute
for the autoincremented columns to Identity, this may be the reason.
We don't have an opportunity to set this attribute automatically in Oracle.


thanks, it works well after i set the StoreGeneratedPattern attribute

http://msdn.microsoft.com/en-us/library/bb738536.aspx
intiwilly
 
Posts: 3
Joined: Fri 08 Jan 2010 08:37


Return to dotConnect for Oracle