I'm using the membership provider asp.net mvc 4.
I'd like to get a list of users and their roles without Roles.GetRolesForUser() for each user.
In my application, the business requirements state that a user will only ever be assigned one role.
What I'm currently doing:
    [GridAction]
    public ActionResult _GetUsers()
    {
        var users = Membership.GetAllUsers().Cast<MembershipUser>().Select(n => new AdminAccountEditModel
        {
            Role = Roles.GetRolesForUser(n.UserName).FirstOrDefault(),
            IsApproved = n.IsApproved,
            Email = n.Email,
            UserName = n.UserName
        }).ToList();
        return View(new GridModel(users));
    }
Very inefficient. How do I fix this?
Thanks.
In the past I've cheated somewhat when using the standard membership provider and have written a lot of complex queries directly against the tables in sql. What you're looking for is a simple join.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With