SQL中的in和not in语法对应的LINQ写法

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" });  

//SQL中的in和not in语法对应的LINQ写法  

//相当于查询语句:select * from listAll p where p.name not in(select f.name from listFind)  

var a = (from p in listAll  

         where !(from f in listFind select f.name).Contains(p.name)  

         select p).ToList();  

2.分页查询

int pageSize = 20;//每页记录数  

int pageIndex=1;//当前页  

        //分页  

       list = (from p in list  

             select p).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(); 

 

  

你可能感兴趣的:(not in)