I am very new to the ADO Entity Framework, and I'm looking for the best practice.
Here is the scenario: I have a database with a Person
table and an Address
table. Person
has a foreign key referencing the primary key of Address
, an auto-incrementing int. First, I've created an ADO Entity model with VS 2010, and sure enough the relationship is understood by the IDE.
Now I want to create a Windows Form that allows the user to fill in a Person
's basic info and Address
. Normally, I can just drag the Person
entity onto a blank Windows Form, and VS2010 will automatically create the necessary fields along with the binding. But what extra work do I need to do in order to ensure the following happens when this form is filled out by the user:
- The
Address
portion of the form is saved in theAddress
table - The
Person
information is saved in thePerson
table, along with the primary key of theAddress
created in 1. - The user never touches/sees any primary keys.
I think my confusion is coming from the fact that I am expecting the IDE to do more coding than it's supposed to; If I had to quickly hack this, I'd probably add a click event to the "save" button that first calls SaveChanges() on the Address
followed by the Person
. Is that the best practice, or is there a more accepted way of doing this?