zoukankan      html  css  js  c++  java
  • lambda一些查询语句

    <!--得分数据结构-->
    1
    <Score> 2 <studentid>1</studentid> 3 <courseid>1</courseid> 4 <score>80</score> 5 </Score>
    <!--科目数据结构-->
    1
    <Course> 2 <courseid>1</courseid> 3 <name>攻击力</name> 4 </Course>
    <!--学生数据结构-->
    1
    <Student> 2 <studentid>1</studentid> 3 <name>大娃</name> 4 <sex></sex> 5 <age>13</age> 6 <remark>力大无穷</remark> 7 </Student>
     1 //按年龄排序 
     2 public static List<Student> GetStudentsSortByAge()
     3         {
     4             try
     5             {
     6                //return Global.Data_students.OrderBy(stu => stu.age).ToList();
     7                 return  Global.Data_students.OrderByDescending(stu => stu.age).ToList();
     8             }
     9             catch (Exception exp)
    10             { }
    11             return null;
    12         }
     1 //指定年龄区间
     2 public static List<Student> GetStudentsByAgeBetween(int sage,int bage)
     3         {
     4             try
     5             {
     6                 return Global.Data_students.Where(stu => (stu.age >= sage && stu.age < bage)).ToList();
     7             }
     8             catch (Exception exp)
     9             { }
    10             return null;
    11         }
    //姓名模糊查询
    public static List<Student> GetStudentsByNameContains(string name)
            {
                try
                { 
                    return Global.Data_students.Where(stu =>stu.name.Contains(name)).ToList();
                }
                catch (Exception exp)
                { }
                return null;
            }
    //指定性别查询
    public static List<Student> GetStudentsBySexIs(string sex)
            {
                try
                {
                    return Global.Data_students.Where(stu => stu.sex==sex).ToList();
                }
                catch (Exception exp)
                { }
                return null;
            } 
     1 //多表查询
     2 public static List<Result> GetScores()
     3         {
     4             try
     5             {
     6                 List<Result> lr = new List<WindowsFormsApplication1.Result>();
     7                 foreach (var v in Global.Data_scores.Join(Global.Data_courses, score => score.courseid, course => course.courseid, (score, course) => new
     8                 {
     9                     studentid = score.studentid,
    10                     coursename = course.name,
    11                     scores = score.score
    12                 }).Join(Global.Data_students, score => score.studentid, student => student.studentid, (score, student) => new
    13                 {
    14                     studentname = student.name,
    15                     coursename = score.coursename,
    16                     scores = score.scores
    17                 }).ToList()
    18                 )
    19                 {
    20                     Result r = new Result();
    21                     r.coursename = v.coursename;
    22                     r.score = v.scores;
    23                     r.studentname = v.studentname;
    24                     lr.Add(r);
    25                 };
    26                 return lr;
    27             }
    28             catch (Exception exp)
    29             { }
    30             return null;
    31         }
  • 相关阅读:
    5-JVM常用的命令
    4-JVM 参数
    3-JVM垃圾回收算法和垃圾收集器
    2-JVM内存结构
    1-JVM基础
    非常短的git学习笔记
    白话马尔科夫链蒙特卡罗方法(MCMC)
    写了个小游戏,来玩
    胡小兔的 高考2019 游记
    机房志 | 一篇中二的文章
  • 原文地址:https://www.cnblogs.com/dyfisgod/p/7053943.html
Copyright © 2011-2022 走看看