• Linq常用



    1、左关联查询
    var lst = from m in db.信息
              join d in db.明细信息
              on m.单号 equals d.单号 into mi
              from dt in mi.DefaultIfEmpty()   //dt标示右表
              where m.单号 == "2014" && dt.编码.StartsWith("1")
              select new
              {
                  单号 = m.单号,
                  版本 = m.版本,
                  编码 = dt.编码
              };

    2、动态拼接where查询语句
    var lst = from m in db.信息
              join d in db.明细信息
              on m.单号 equals d.单号 into mi
              from dt in mi.DefaultIfEmpty()   //dt标示右表
              select new
              {
                  单号 = m.单号,
                  版本 = m.版本,
                  编码 = dt.编码
              };

    lst = lst.Where(p => p.单号.Contains("11") || p.编码.Contains("11"));


    var newList = lst.Select(p => new { p.单号, p.版本 })   //只使用左表数据作为查询结果
                 .Distinct().OrderBy(p => p.单号).Skip(0).Take(10).ToList();

    3、in
    from p in 信息
    where (new string[] {"10","14"}).Contains(p.编码)
    select p

    4、not in
    from p in 信息
    where !(new string[] {"10","14"}).Contains(p.编码)
    select p

  • 相关阅读:
    7. ZooKeeper的stat结构
    6. ZooKeeper访问控制列表
    5. 监视和ZooKeeper操作
    4. ZooKeeper 基本操作
    3.Apache ZooKeeper数据模型
    Eclipse安装Activiti Designer插件
    Javascript Canvas验证码
    Tomcat9配置SSL连接
    JAVA将异常的堆栈信息转成String
    SpringBoot2静态资料访问
  • 原文地址:https://www.cnblogs.com/gossip/p/3785549.html
Copyright © 2020-2023  润新知