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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:12+00:00 2026-05-23T12:19:12+00:00

I’m probably going about this the wrong way, please feel free to correct me.

  • 0

I’m probably going about this the wrong way, please feel free to correct me.

Currently I have a User model called U_USER, it contains fields such as address, receiveNotifications, HasCompanyCar Etc.

These users have roles in a .NET Membership table. When the user logs in via Membership, I get their user record in my database as follows (the username on the Membership table and my own U_USER table will have a match):

        //Gets the current user
        public U_USER CurrentUser()
        {
            return GetUser(HttpContext.Current.User.Identity.Name);
        }

        //Gets user details by username
        public U_USER GetUser(String username)
        {
            return (from u in db.U_USER
                   where u.UserName == username
                   select u).FirstOrDefault();
        }

If I wanted to get a list of all users in, lets say, the “Create” role then I would do this:

allUsers.Where(x => Roles.IsUserInRole(x.UserName, "Create"))

This is a big performance hit as it’s doing a lookup for each iteration of a user. This makes me think I’m not going about user management in the correct way. So to answer this question:

How should you properly connect Membership to a users table that in turn is connected to the rest of your data? I’d also accept how to just go about it more efficiently!

Many thanks 🙂

EDIT :

I’ve increased performance via the below code. I get the users in the role in one swoop and then filter them.

String[] usersInRole = Roles.GetUsersInRole("CanApprove");
users = users.Where(x => usersInRole.Any(y => y == x.UserName));

But I’m still fairly sure I’m going about this ALL wrong!

  • 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-23T12:19:13+00:00Added an answer on May 23, 2026 at 12:19 pm

    Not an expert in this, but what my apps typically do is to use a foreign key (with Index) from my own Users table to the Membership Users table using the Guid field with the Membership. This then allows me to do queries using Linq like:

     var query = from myUser in MyUsers
                join aspUser in aspnet_Users on myUser.UserId equals aspUser.UserId
                join usersInRole in aspnet_UsersInRoles on aspUser.UserId equals usersInRole.UserId
                join role in aspnet_Roles on usersInRole.RoleId equals role.RoleId
                where role ...
                select new { ... };
    

    (Or you can use dot-form like myUser.AspUser.Roles.Role to let the ORM generate the joins if you prefer)

    For performance, it’s good to watch the SQL trace occasionally – make sure you’re not making too many SQL round-trips for each logical step in code.

    Hope that helps a bit.


    Update – in answer to your questions about “should you even do that”, I think “yes” but there are other options available – e.g. you can use Profile fields – see Step 6 in this great walkthrough – https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.