Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOT IN for LINQ?

Tags:

c#

asp.net

linq

Is there a way for me to filter Employees by group: ex:

List<String> notInGroups = GetNotInGroups();

    var list = from p in employees 
    where p.Group.Name notin(notInGroups)
    select p;

Is there some way to do something like this?

Thanks

like image 864
jmasterx Avatar asked Dec 15 '22 13:12

jmasterx


1 Answers

You can do !Contains, like:

var list = from p in employees
where !notInGroups.Contains(p.Group.Name)
select p;
like image 141
Joe Enos Avatar answered Jan 08 '23 04:01

Joe Enos