Start New Discussion within our Software Development Community

Assuming that my DB looks similar to the following:

User
    UserId
    ...

PhoneNumber
    PhoneNumberId
    ...

UserPhoneNumber
    UserId
    PhoneNumberId

When I use EF and insert a record into User (that also has PhoneNumbers attached to it), it auto inserts into PhoneNumber and UserPhoneNumber. I can also update User and update PhoneNumber. However if I need to add a new record to PhoneNumber for a user after the inital creation it is only ever inserted into PhoneNumber and not into UserPhoneNumber creating to association.

The UserPhoneNumber shows up as a relationship in the EDMX and not as a table so I have no way to insert directly into it.

There are solutions like adding a dummy field to allow the table to show up, however this is a hack.

I'm not looking for someone to code this for me, if you can just point me in the right direction or give me a site I can look at for a solution that would be great.

P.S. Yes, I've googled this and have spent several hours researching this.

Thanks

ok, figured it out. I did the following:

db.Companies.Find(company.CompanyId).PhoneNumbers.Add(phoneNumber);

where db is the DB context.

This article has been dead for over six months. Start a new discussion instead.