asp.net mvc - MVC Identity 2.1 - get a list of users NOT in a particular role -


how list of users not in 1 particular role? using mvc 5, ef 6, identity 2.1.

to list of users in "host" role can do:

var getrole = (from r in db.roles r.name.contains("host") select r).firstordefault(); var gethostusers = db.users.where(x => x.roles.select(y => y.roleid).contains(getrole.id)).tolist(); 

to list of users can do:

var getusers = await db.users.where(u => u.id != currentuser).orderby(u => u.firstname).tolistasync(); 

but need list of users not in "host" role (getusers - gethostusers).

if want users, except host role can opposite of doing , add exclamation mark in clause.

var getrole = (from r in db.roles r.name.contains("host") select r).firstordefault(); var getnothostusers = db.users.where(x => !x.roles.select(y => y.roleid).contains(getrole.id)).tolist(); 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -