Search code examples
asp.netasp.net-mvcasp.net-mvc-5asp.net-membershipasp.net-authentication

Get all users and profile fields in 1 database call


We currently have a page on our website that gets all our users and lists them.

var users = Membership.GetAllUsers();

This page then makes a Profile call for each user as it loops through them in the view.

foreach (MembershipUser user in Model)
{
    ProfileBase pb = ProfileBase.Create(user.UserName, true);
    //display fields
}

This makes the page load very slowly and is getting worse as we add more users. At over 4000 now the page can take a minute or 2 to load. Luckily it's just an admin page, but I'd still like to make it more efficient.

Is there an efficient way I can do all of this in 1 call to the database?


Solution

  • I ended up just recoding the entire site not to use ProfileBase. I really can't recommend anyone ever implement it.