LINQ中的In和Not In

1.SQL中的in和not in 语法

select * from table1 where column1 = 2016 and column2 ='ZY' and column3 not in(select column3 from table2);

2.LINQ中的in和not in用法

List<testInfo> listAll = new List<testInfo>(); 
listAll.Add(new testInfo() { id = 1, name = "11", test = "111" }); 
listAll.Add(new testInfo() { id = 2, name = "22", test = "222" }); 
listAll.Add(new testInfo() { id = 3, name = "33", test = "333" }); 
listAll.Add(new testInfo() { id = 4, name = "33", test = "333" }); 
   
List<testInfo> listFind = new List<testInfo>(); 
listFind.Add(new testInfo() { id = 1, name = "44", test = "111" }); 
listFind.Add(new testInfo() { id = 2, name = "22", test = "222" }); 
listFind.Add(new testInfo() { id = 3, name = "33", test = "333" }); 
listFind.Add(new testInfo() { id = 4, name = "55", test = "333" }); 

var a = (from p in listAll 
         where !(from f in listFind select f.name).Contains(p.name) 
         select p).ToList(); 
posted @ 2022-04-05 20:51  小堂子  阅读(205)  评论(0编辑  收藏  举报