I have database tables like this:
TABLE: User
UserId
UserName
TABLE: UserToOrganization
UserId
OrganizationId
TABLE: Organization
OrganizationId
Organization
I’m using Entity Framework and since the UserToOrganization table is just made up of foreign keys Entity Framework hides this table. I would like to associate a User to an Organization by adding an User.UserId and an Organization.OrganizationId to the UserToOrganization table. However, since the UserToOrganization table is hidden, how do I add a row to this table in the database using Linq?
Thank you,
Aaron
Okay, figured it out. Seems obvious now that I think about it.
Here are my EF Tables as they are laid out in the edmx file (I probably should have provided this in my original question). Notice that
Userhas anOrganizationsandOrganizationhas anUsers.TABLE: User
UserId
UserName
Navigation Properties
Organizations
TABLE: Organization
OrganizationId
Organization
Navigation Properties
Users
Here is how an insert is done on the hidden “UserToOrganization” FK table:
Step 1: Make sure that your foreign key table’s columns are both primary keys.
Setp 2: Insert.
Thank you for your help,
Aaron