I am using mvc 4 with entity framework. I need a list of all users that have not yet been assigned any role. I cannot find any predefined function in Role.
Output will be.
My current code is as following.
var users = db.UserProfileEFMs
.ToList()
.Where(o => !Roles.GetRolesForUser(o.UserName).ToList<string>().Any())
.ToList();
but it is not working properly or is too slow. Is there any another way to get that kind of list.
I am looking for an Extentions method for Roles like.
public static class Extentions
{
public static List<string>/*UserName*/ UsersNotInAnyRole(this Roles /*System.Web.Security*/ roles)
{
/*----code----*/
}
}
currently i am using the following code
var users = db.Database.SqlQuery<UserProfile>("select * from dbo.UserProfile where UserId not in(select UserId from dbo.webpages_UsersInRoles)").ToList();
I don't get better solution. I think following is the best one.
var users = db.Database.SqlQuery<UserProfile>("select * from dbo.UserProfile where UserId not in(select UserId from dbo.webpages_UsersInRoles)").ToList();