linq2sql beta: insert parent/child rows in one submitchanges
Posted: Tue 14 Oct 2008 12:40
Hi,
I've tried to insert parent and child rows in one db.submitchanges(), the childobject has a foreign key relationship to the parentobject
Like this:
As described here : http://forums.microsoft.com/MSDN/ShowPo ... 1&SiteID=1
But that doesnt't work, i cannot add a childobject to a parentobject.
My workaround at the moment is the following:
It is important to add the childobject first, otherwise a FK relationship error is thrown.
I've tried to insert parent and child rows in one db.submitchanges(), the childobject has a foreign key relationship to the parentobject
Like this:
Code: Select all
ParentObject po = new ParentObject();
ChildObject co = new ChildObject();
po.Childobjects.add(co);
db.ParentObjects.insertOnSubmit(po);
db.SubmitChanges();
But that doesnt't work, i cannot add a childobject to a parentobject.
My workaround at the moment is the following:
Code: Select all
childobject.insertonsubmit(co);
parentobject.insertonsubmit(po);
db.submitchanges();