sequence of saving parent/child records
Posted: Thu 01 Oct 2009 10:06
I need to create first child record and then parent record.
SubmitChanges() generates the exception "Error on executing DbCommand.", because the insert command for child records is generated first.
Can LINQ generate insert commands in right sequence (depending on the relations), or is there any way to do this manually ?
Code: Select all
Testdatacontext dc = new Testdatacontext();
Testchild tc = new Testchild();
tc.Text = "one";
dc.Testchilds.InsertOnSubmit(tc);
...
...
Test t = new Test();
t.Text = "numbers";
dc.Tests.InsertOnSubmit(t);
tc.Test = t;
...
dc.SubmitChanges();
Can LINQ generate insert commands in right sequence (depending on the relations), or is there any way to do this manually ?