ambda表达式查询没有IN这个方法,可以变通一下,in查询的数组是否包含在映射对象里面的集合里
直接贴代码吧,一看就懂了
class Program { static void Main(string[] args) { List<Model> strList = new List<Model>() { new Model(){Id=1,Name = "张三"}, new Model(){Id=2,Name = "李四"}, new Model(){Id=3,Name = "王五"}, new Model(){Id=4,Name = "赵六"}, }; List<int> whereList = new List<int>(){1,3}; var list = strList.Where(x => whereList.Contains(x.Id)); foreach (var model in list) { Console.WriteLine("Id:"+model.Id+"Name:"+model.Name); } Console.ReadKey(); } } public class Model { public int Id { get; set; } public string Name { get; set; } }
运行结果:
来源:https://www.cnblogs.com/jellydong/p/10031237.html