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 4571494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:30:43+00:00 2026-05-21T19:30:43+00:00

I have two tables User and UserRole which are they connected using a link

  • 0

I have two tables User and UserRole which are they connected using a link table UserInRole

When I generate the entity model, for some reason, the entity UserInRole not getting generated. And as you can see from the picture, Entity Framework understood that there is many-to-many relationship between User and UserRole:

enter image description here

I need to implement the query like this

select ur.Name from [User] as u
inner join UserInRole uir on uir.UserId = u.Id
inner join UserRole ur on ur.Id = uir.UserRoleId
where u.Username = 'magename'

I am using generic repository, if navigation property would exists the query would be looking like this:

from u in repository.AsQueryable<User>()
join uir in repository.AsQueryable<UserInRole>() on u.Id equals uir.UserId
join ur in repository.AsQueryable<UserRole>() on uir.UserId equals ur.Id
where u.Username == userName
select ur.Name

But Entity Framework does not generate UserInRoles navigation property and related UserInRole entity, so the question what should I do in that situation? Should I remove link between UserInRole and UserRole to get entity UserInRole generated in model or there any way to have the query I described above without any changes in database?

UPDATED

so looks i need to do something like that

stirng[] roles = (from u in repository.AsQueryable<User>()
         where u.Username == userName
         select ur.UserRoles.Select(x => x.Name)).ToArray<string>();

getting an error Cannot implicitly convert type 'System.Collections.Generic.List<System.Collections.Generic.IEnumerable<string>>' to 'string[]' any ideas?

  • 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-21T19:30:43+00:00Added an answer on May 21, 2026 at 7:30 pm

    You don’t need that link table in your EF model! That’s the beauty of EF!!

    Check your entity User – it has a UserRoles navigation property – that’s the collection of all roles this user is in.

    Check out entity UserRole: it has a navigation property Users which has all users that are in this role.

    With these two multi-valued navigation properties, you can express any of the queries you might want:

    • find all users for a given role (find the UserRole entity and enumerate its .Users property)
    • find all roles for a given user (find the User and enumerate its .UserRoles)

    EF and the EDM sort of “hide” that link table from you – you don’t really need it when you’re expressing your intent in the conceptual model; those link tables are just a “necessary evil” in relational databases since those databases cannot model m:n relationships in any other way.

    Update: so you seem to want to find a list of all the user roles (their names) that a particular user is in – you can express this something like this:

    // find the user in your "dbContext" (or via your repository)
    var user = _dbContext.Users.FirstOrDefault(u => u.Name == "magename");
    
    // from the list of UserRoles on that user, select the names only
    var userRolesNames = user.UserRoles.Select(ur => ur.Name).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have two tables User and Pictures im trying to pull the pathname
Let's say I have two tables as shown: user id plan course_limit username 10
i have two tables Table1 with columns user_name,Password and course ID and another table
I have two tables defined as the following: User (ID int, name varchar) Hours
I have two tables: projects and user_licenses . I'd like to grab the entire
i have two tables item_tb | item_id | user_id | --------------------- user_tb | user_id
We have a web application where we need to create functionality to manage users,
Maybe a quite easy question but I'm new in Linq to SQL. I have
I'm having some trouble with NHibernate, while trying to remove an object describing a

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.