Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:20:05+00:00 2026-06-07T12:20:05+00:00

I have database tables like this: TABLE: User UserId UserName TABLE: UserToOrganization UserId OrganizationId

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:20:07+00:00Added an answer on June 7, 2026 at 12:20 pm

    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 User has an Organizations and Organization has an Users.

    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.

    public void AddUserToOrganization(Guid UserId, int OrganizationId)
    {
        // Get the user and the organization that you want to join
        var user = _data.Users.First(x => x.UserId == UserId);
        var org = _data.Organizations.First(x => x.OrganizationID == OrganizationId);
        // Add the organization to the user
        user.Organizations.Add(org);
        // Save
        context.SaveChanges();
    }
    

    Thank you for your help,

    Aaron

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my database who looks like this: User: userid(int) username(varchar)
Hi i have database like this Users Table user_id | username | branch_id(foreignkey)| Approved_id(foreignkey)
I have a database with three tables set up like this: Users : username,
I have a table in my database like this: [id] [uniqueidentifier] NOT NULL, [user_id]
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database application in which a group is modeled like this: TABLE
I always forget how to do things like this. I have a database table
I have a table like this in my database (SQL Server 2008) ID Type
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a question. My database table is something like this: | ID |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.