I am trying to create a new instance of a Customer entity in our application, and I am having a few problems. This entity has several navigational properties, each of which has their own nav. properties. For example, each Customer entity has an Address entity, and each Address entity has a Phone Number entity etc. I haven't figured out how to get the new data set for all of those entities. I've tried the following:
context.Customers newCustomer = context.Customers.CreateCustomer(...);
newCustomer.FirstName = firstNameTextBox.Text;
newCustomer.Address.Street = streetTextBox.Text; // this is where the error is thrown
At this point, I get an "Object reference not set to an instance of an object" error because Address is null. I had originally assumed that creating the new customer entity would automatically create a new instance of each entity that it is related to, but this must not be the case. Can someone provide a code example of how this is supposed to work? Thanks.