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();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。