var usersFilterRoles = from u in dataContext.aspnet_Users
join p in dataContext.Partners on u.UserId equals p.Id
where u.aspnet_Roles.Contains(roles)
not worked. roles - I do RoleId or nameRole
I need get users by roles
var usersFilterRoles = from u in dataContext.aspnet_Users
join p in dataContext.Partners on u.UserId equals p.Id
where u.aspnet_Roles.Contains(roles)
not worked. roles - I do RoleId or nameRole
I need get users by roles
Get all user names using Roles.GetUsersInRole Method and If you need more information then use Membership.GetAllUsers() to get all users from the Membership
and retrieve the Role users from the return MembershipUserCollection
either using linq or loop
through MembershipUserCollection and add to custom collection; which method you like best.
MembershipUserCollection users;
string[] usersInRole;
rolesArray = Roles.GetAllRoles();
users = Membership.GetAllUsers();
Check GetUsersIndRole
method's link example to clear about the logic.
Expected Linq Query:
string[] usersInRole = Roles.GetUsersInRole("Role");
var users = DataContext.AspnetUsers.Where(usr => usersInRole.Contains(usr.LoweredUserName));
Follow these tutorials and Links for working with membership.
ASP.NET's Membership, Roles, and Profile
How do you manage asp.net SQL membership roles/users in production?
Using the ASP.NET Role and Membership provider is the way to go but if you want to get the users by role in linq:
var userRoleQuery = from anu in context.AspNetUsers
where anu.AspNetRoles.Any(r => r.Id == roleId)
select anu.Id
why not using System.Web.Security.Roles ?
using System.Web.Security;
namespace App.SomeName
{
public class YourClass
{
public void GetUsers(){
string[] users = Roles.GetUsersInRole("MyRole");
}
}
}
Is this what you wanted to do ?