How to create a linq query that gets everything but a specific value

Let's say that I have a linq r query request in db.Roles, where r.RoleName does NOT contain ("Administrator") selects r;

It does not contain the part that bothers me. I understand that I can do this. Calls, but how do you do the opposite?

Thank!

Update: I found the Exclude method, and here is how I used it:

var role = (from r in db.Roles
            orderby r.RoleName
            select r)
           .Except(from r in db.Roles 
                   where r.RoleName == "Administrator" & r.RoleName == "DataEntry" 
                   select r
            );
+2
source share
2 answers

Try to execute

var query = db.Roles.Where(x => !x.RoleName.Contains("Administrator"));

You can simply use the C # not operator! (Exclamation point). Extended LINQ Syntax

var query = 
  from it in db.Roles
  where !it.RoleName.Contains("Administrator")
  select it;
+9
source
+3

All Articles