Klaus basically already determined what you need to do - try this code:
using (DatabaseDataContext db = new DatabaseDataContext()) { Customer newCustomer = new Customer() { Email = customer.Email }; Address b = new Address() { Address1 = billingAddress.Address1 }; newCustomer.Address = b; db.Customers.InsertOnSubmit(newCustomer); db.SubmitChanges(); }
If you linked address b to the client you just created, then paste that client into the db.Customers collection, calling db.SubmitChanges() should automatically save the address, save the client, and correct any of the IDENTITY columns to make this work. This really works for me in a test case.
You cannot use the address or customer ID yet - they have not been set yet. But you can definitely link complete objects to each other and thus get a โconnectionโ between the two places.
To do this, you need to make sure that in the DBML design in the Properties window for both columns of the Auto Generated Value identifier is True , and Auto-Sync is ste until OnInsert (both of which are not default values).
source share