LINQ其中列表 [英] LINQ where in List

查看:105
本文介绍了LINQ其中列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目列表的ID



IEnumerable的项目



这包含四个数字,比方说2, 5,6,9



这是我AllProjects

 的IEnumerable< ;项目> AllProjects =等待ctx.Projects.Where(X => x.ClientID ==客户端ID)。凡(Y => y.Released == true)而.ToListAsync(); 



我要与项目的ID过滤我AllProjects 2,5,6,9



应该有的东西一样...

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

感谢


解决方案

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

您只需要检查的项目列表中包含你正在寻找


的ID

i have list of projects iD

IEnumerable projects

That contains four numbers ,let's say 2,5,6,9

and this is 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

should be some thing like ...

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

Thanks

解决方案

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

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

这篇关于LINQ其中列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆