Page 1 of 1

Parent - Child insert with .Net Entity Framework

Posted: Fri 08 Jan 2010 08:56
by intiwilly
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 ... bc480ee8a/

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,

Posted: Tue 12 Jan 2010 10:00
by AndreyR
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.

Posted: Thu 21 Jan 2010 09:24
by intiwilly
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