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

  • SEARCH
  • Home
  • 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 6556931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:00:32+00:00 2026-05-25T13:00:32+00:00

First, sorry for my english. Second, I’m not good at database modeling, so I

  • 0

First, sorry for my english.
Second, I’m not good at database modeling, so I might be completely wrong.

I’m writing a website (think of it as a forum), where in every post, each user can have a different roles.

The way I would do it without using entity framework is creating 3 tables:

  • User
  • Group
  • Role
  • UserGroupRole

Where UserGroupRole would contain the keys for the 3 tables.

How can I do it with entity framework?

Maybe the whole aproach is incorrect, I’m not sure.

Thanks in advance!

  • 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-05-25T13:00:33+00:00Added an answer on May 25, 2026 at 1:00 pm

    Yes, I would probably also work with 4 entities and tables. In EF 4.1 something along these lines:

    public class User
    {
        public int Id { get; set; }
        public ICollection<UserGroupRole> UserGroupRoles { get; set; }
    }
    
    public class Group
    {
        public int Id { get; set; }
        public ICollection<UserGroupRole> UserGroupRoles { get; set; }
    }
    
    public class Role
    {
        public int Id { get; set; }
        public ICollection<UserGroupRole> UserGroupRoles { get; set; }
    }
    
    public class UserGroupRole
    {
        [Key]
        public int UserId { get; set; }   // FK property
        [Key]
        public int GroupId { get; set; }  // FK property
        [Key]
        public int RoleId { get; set; }   // FK property
    
        public User User { get; set; }
        public Group Group { get; set; }
        public Role Role { get; set; }
    }
    

    The foreign key properties enforce all three relationships to be required (null is not allowed) and the complex key over all three Ids ensure that any combination of user, group and role can only exist once. You can remove some of the navigation collections – for example in Group and Role – if you don’t need them.

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

Sidebar

Related Questions

first of all sorry for my English :-) not so good. I have a
First of all, sorry about that title. I'm not the best at writing those
First Sorry for my English. I wanted to ask why ElementName does not work
First of all, I need to say that my English is not good. So
First - sorry for my english;) I'am writing profile manager for Android and i
First, sorry for bad english :-) On a little website i own, i would
First,sorry to my bad english. I don't understand why my page not refresh when
this is my first question and I'm not English native speaker so sorry for
First I am sorry if I posted at the wrong place. Now onto the
First of I'm very sorry but this questions is not so so specific. All

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.