<pre><code>var e1 = new E1();
e1.e2s.Add(new e2()); //e2s is null until e1 is saved, i want to save them all at the same time
context.e1s.imsertonsubmit(e1);
context.submitchanges();
</code></pre>

[{'answer_id': 52870, 'author': 'John Christensen', 'author_id': 1194, 'author_profile': 'https://Stackoverflow.com/users/1194', 'pm_score': 0, 'selected': False, 'text': "<p>Well - I don't know if your initial code block would work, but I'm guessing you have to mark your new e2 as insert on submit. Thus:</p>\n\n<pre><code>var e1 = new E1();\nvar e2 = new e2();\ne1.e2s.Add(e2); //e2s is null until e1 is saved, i want to save them all at the same time\ncontext.e1s.insertonsubmit(e1);\ncontext.e2s.insertonsubmit(e2);\ncontext.submitchanges();\n</code></pre>\n"}, {'answer_id': 53018, 'author': 'Gabe Anzelini', 'author_id': 5236, 'author_profile': 'https://Stackoverflow.com/users/5236', 'pm_score': 0, 'selected': False, 'text': '<p>there we go, apparently when you create another ctor, you have to actually call the no arg ctor in order for the stuff in the ctor to happen</p>\n'}, {'answer_id': 91471, 'author': 'Sam', 'author_id': 7021, 'author_profile': 'https://Stackoverflow.com/users/7021', 'pm_score': 1, 'selected': False, 'text': "<p>The sub items will be saved along with the main item, and even identities will be set properly, if you give your DataClasses an association between these classes.</p>\n\n<p>You do this by adding LoadOptions to your O/R-Designer DataClasses like this:</p>\n\n<pre><code>  MyDataContext mydc = new MyDataContext();\n  System.Data.Linq.DataLoadOptions lo = new System.Data.Linq.DataLoadOptions();\n  lo.LoadWith&lt;E1&gt;(p =&gt; p.e2s);\n  mydc.LoadOptions = lo;\n</code></pre>\n\n<p>This way LINQ will take care of adding the sub-items, you don't need to InsertOnSubmit every one by itself.\nA side effect: upon loading the item, the subitems will be retrieved, too.</p>\n"}]
['https://Stackoverflow.com/questions/52821', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5236/']