1.主要是借住contains和where完成嵌套
//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个list为数据源,进行数据筛选,则可以使用lambda表达式,如下所示:
List list=list1.where(o=>list2.name.contains(o.name)).ToList();
2.分页查询
int pageSize = 20;//每页记录数 int pageIndex=1;//当前页 //分页 list = (from p in list select p).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();