zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    复数除法
    base operand of '->' has non-pointer type 'const Comple
    virtual关键字
    & 引用
    const用法
    Iptable与firewalld防火墙
    存储结构与磁盘划分
    Linux系统中用户身份与文件权限
    计时器小程序——由浅入深实例讲解
    ASP.NET编程十大技巧(他人总结)
  • 原文地址:https://www.cnblogs.com/gossip/p/3785549.html
Copyright © 2011-2022 走看看