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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:01:13+00:00 2026-05-24T08:01:13+00:00

My schema is a fairly straight-forward membership and roles schema: Users table: UserId (PK)

  • 0

My schema is a fairly straight-forward membership and roles schema:

Users table:
UserId (PK)
UserName
etc...

Roles table:
RoleId (PK)
RoleName

UsersInRole table
UserId (FK to Users table)
RoleId (FK to ROles table)

So, we’ve got the many-to-many table UsersInRole along with the other two tables. When I add the schema into EF, the generated ORM code (and the EF designer) only shows Users and Roles (no problem, EF manages the many-to-many).

So, here’s my question. I want to list all the users who do not have the role “Super Admin”. Seems like a simple problem, just use a SelectMany in EF. The problem is a user may have multiple roles, one of which is “Super Admin”. If I use the SelectMany (like below), I will still get those users who have “Super Admin” in addition to other roles. The SelectMany only works if the user has one role and that role is “Super Admin”

I’ve tried to put together SQL to work from that to the Linq-to-EF, but haven’t had any luck doing that either.

var usrQry = context.Roles.Where(r => r.RoleName != "Super Admin")
        .SelectMany(r => r.Users);

Any help is appreciated – 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-24T08:01:14+00:00Added an answer on May 24, 2026 at 8:01 am

    Your query will also return the same users multiple times. You are better to go back to your original statement and try to make the code look more like it.

    Your statement was:

    I want to list all the users who do not have the role “Super Admin”

    So here is the code to do that.

    var userQry = context.Users.Where(
                    u => !u.Roles.Any(r => r.RoleName == "Super Admin"));
    

    in LINQ syntax:

    var userQry = from u in context.users
                  where !u.Roles.Any(r => r.RoleName == "Super Admin")
                  select u;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Schema: Users ID Name Password Address ID Street UserID Both tables have an ID
It seems to be fairly accepted that including the schema owner in the query
My schema is as follows: The airports table holds airport names. It's primary key
Fairly new to database schema (plan to use SQLite). Having said that, I'm thinking
I have a fairly simple table requestparams ( requestid varchar(64) NOT NULL, requestString text,
We've found an error in the code for multi-schema databases in ActiveRecord (we're fairly
First the relevent schema: A is a table of list entries with ListID, Date,
I'm working on a fairly simple survey system right now. The database schema is
I'm working on a project with a fairly large SQL Server database. The schema
This is a fairly quick question regarding schema design for a Django project. Basically,

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.