Entity framework - Multiple foreign keys to same table causing data to be updated incorrectly
===

I have the following 2 tables in my database:

    Address:
    
    Street1
    City
    State
    Zipcode

    Customers:
    
    Name
    LocationAddressId (FK to Address table)
    MailingAddressId (FK to address table)

I generated Entity framework model for this. When I create a customer object and populate only LocationAddress but not MailingAddress, an id (primary key for address table) is generated for LocationAddress. This id is assigned to LocationAddressId and the same id is being assigned to MailingAddressId as well. 

Here is the code I have:

  

    Customer c = new Customer();
      var a = new Address
      {
            Street1 = "Test",
            City = "test",
            Zip = "43343",
            Country = "sdf",
      };
    
    
    c.Address = a;
    
    c.Name = "Test Customer";
    ctx.Customers.AddObject(c);
    ctx.SaveChanges();

After I save the changes, c.LocationAddressId and c.MailingAddressId are the same even though I didn't assign anything to Mailing Address.

Problem #2: 

In my code, when I try to create MailingAddress as well, I Get the error "Unable to determine the principal end of the 'TestModel.FK_Customer_LocationAddress_Address' relationship. Multiple added entities may have the same primary key.Below is the code:

    Customer c = new Customer();
      var a = new Address
      {
            Street1 = "Test",
            City = "test",
            Zip = "43343",
            Country = "sdf",
      };
    
    
    c.Address = a;
      var b = new Address
      {
            Street1 = "Test mailing addr",
            City = "test",
            Zip = "43343",
            Country = "sdf",
      };
    
    c.Address1 = b;
    
    c.Name = "Test Customer";
    ctx.Customers.AddObject(c);
    ctx.SaveChanges();

I am not sure if I am creating the objects the right way. Does anyone have any ideas as to what is causing the issues?

Thanks





