zoukankan      html  css  js  c++  java
  • LINQ多表查询

    View Code

    #region Group,Join

    //只有join,没有into,内联(inner join)

    //var sql = from c in sdb.Classic

    // join s in sdb.StuInfo

    // on c.classID equals s.classID //注意不能用==

    // select new // { // c.className, // s.stuName // };

    //Console.WriteLine(sql);

    //var sql = from s in sdb.StuInfo

    // join m in sdb.StuMarks

    // on s.stuNo equals m.stuNo

    // into temp

    //many端重新命名

    // from t in temp.DefaultIfEmpty() //左连接,DefaultIfEmpty再次遍历右边,缺考人员的成绩默认为null

    // select new

    // { // s.stuName, // we = t.writtenExam == null ? 0 : t.writtenExam, // le = t.LabExam == null ? 0 : t.LabExam // };

    //Console.WriteLine(sql);

    //foreach (var item in sql)

    //{ // Console.WriteLine("{0} {1} {2}",item.stuName,item.we,item.le); //}

    //三向联接

    //var sql = from c in sdb.Classic

    // join s in sdb.StuInfo

    // on c.classID equals s.classID

    // join m in sdb.StuMarks

    // on s.stuNo equals m.stuNo

    // select new

    // { // c.className,

    // s.stuName,

    // we = m.writtenExam == null ? 0 : m.writtenExam,

    // m.LabExam // };

    //Console.WriteLine(sql);

    //foreach (var item in sql)

    //{

    // Console.WriteLine("{0} {1} {2} {3}", item.className, item.stuName, item.we, item.LabExam);

    //}

    //双向连接 var sql = from c in sdb.Classic join s in sdb.StuInfo on c.classID equals s.classID into stu select new { className = c.className, list=stu.ToList<StuInfo>(), count = stu.Count() }; Console.WriteLine(sql); foreach (var item in sql) { Console.WriteLine("班级:{0},人数:{1}",item.className,item.count); foreach (var s in item.list) { Console.WriteLine(s.stuName); } }

    #endregion

  • 相关阅读:
    iOS- static extern const
    App 性能分析
    迭代器和生成器
    软件工程之个人软件开发----起步
    myeclipse调式与属性显示
    hdu 6188
    uva10780 质因子分解
    云服务器端口号的几个操作
    Redis错误 : MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.
    ubuntu系统安装宝塔面板Linux版
  • 原文地址:https://www.cnblogs.com/yyx999/p/13291676.html
Copyright © 2011-2022 走看看