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; } }
运行结果:
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。