tags:

views:

67

answers:

2

Say I have a linq query select r in db.Roles where r.RoleName DOES NOT contain ("Administrator") select r;

It is the does not contain part that has me confused. I realize I can do that .Contains call but how do you do the opposite?

Thanks!

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);

+8  A: 

Try the following

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

You can just use the C# not operator ! (exclamation point). Expanded LINQ syntax version

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

If you had multiple roles to exclude, you might take a look at the Except function.

mquander