LINQ where in the list

I have a list of projects iD

IEnumerable projects

This contains four numbers, say 2,5,6,9

and these are my AllProjects

 IEnumerable<Project> AllProjects = await ctx.Projects.Where(x => x.ClientID == clientid).Where(y => y.Released == true).ToListAsync();

      

I want to filter my AllProjects with project id 2,5,6,9

it should be something like ...

 AllProjects = AllProjects.Where(x=>x.ProjectID == ????)

      

thank

+3


source to share


1 answer


AllProjects = AllProjects.Where(x=>projects.Contains(x.ProjectID))

      



You just need to check if the project list contains the id you are looking for

+6


source







All Articles