• 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(); 

      

  • 相关阅读:
    第七周学习总结
    深入理解计算机系统第二章家庭作业
    第六周学习总结
    第五周学习总结
    第四周学习总结
    第三周学习总结
    第二周学习总结
    caffe的特殊层
    Eltwise层解析
    slice层解析
  • 原文地址:https://www.cnblogs.com/huangfenggu/p/4423265.html
Copyright © 2020-2023  润新知