lambda一些查询语句
<!--得分数据结构-->
1 <Score>
<studentid>1</studentid>
<courseid>1</courseid>
<score>80</score>
</Score>
<!--科目数据结构-->
1 <Course>
<courseid>1</courseid>
<name>攻击力</name>
</Course>
<!--学生数据结构-->
1 <Student>
<studentid>1</studentid>
<name>大娃</name>
<sex>男</sex>
<age>13</age>
<remark>力大无穷</remark>
</Student>
//按年龄排序
public static List<Student> GetStudentsSortByAge()
{
try
{
//return Global.Data_students.OrderBy(stu => stu.age).ToList();
return Global.Data_students.OrderByDescending(stu => stu.age).ToList();
}
catch (Exception exp)
{ }
return null;
}
//指定年龄区间
public static List<Student> GetStudentsByAgeBetween(int sage,int bage)
{
try
{
return Global.Data_students.Where(stu => (stu.age >= sage && stu.age < bage)).ToList();
}
catch (Exception exp)
{ }
return null;
}
//姓名模糊查询
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;
}
//多表查询
public static List<Result> GetScores()
{
try
{
List<Result> lr = new List<WindowsFormsApplication1.Result>();
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()
)
{
Result r = new Result();
r.coursename = v.coursename;
r.score = v.scores;
r.studentname = v.studentname;
lr.Add(r);
};
return lr;
}
catch (Exception exp)
{ }
return null;
}
lambda一些查询语句的更多相关文章
- linq与lambda 常用查询语句写法对比
LINQ的书写格式如下: from 临时变量 in 集合对象或数据库对象 where 条件表达式 [order by条件] select 临时变量中被查询的值 [group by 条件] Lambda ...
- 浅谈sql 、linq、lambda 查询语句的区别
浅谈sql .linq.lambda 查询语句的区别 LINQ的书写格式如下: from 临时变量 in 集合对象或数据库对象 where 条件表达式 [order by条件] select 临时变量 ...
- 用lambda构建ORM查询语句
本文介绍如何解析lambda表达式来获取一个满足条件的查询语句. 先看个截图 通过设置实体对象Article_Content的查询表达式,就可以获取对应的参数化SQL语句,使用起来很方便,减少了代码 ...
- CRL快速开发框架系列教程二(基于Lambda表达式查询)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- EF 拉姆达 动态拼接查询语句
EF 动态拼接查询语句 using System; using System.Collections.Generic; using System.IO; using System.Linq; usin ...
- lambda表达式查询经验:IN 和groupby的使用
lambda In的用法: lambda表达式查询没有IN这个方法,可以变通一下,in查询的数组是否包含在映射对象里面的集合里: 如下代码: var departmentIDs = input.Dep ...
- Lambda的分类(语句Lambda和表达式Lambda)
学习自 <C#本质论> Overview 在上一文中,我们简而又简的了解了一下,匿名方法和Lambda表达式,关于匿名方法这里暂且不表,本文我们来更加详细的了解一下Lambda表达式. 本 ...
- EFCore扩展Select方法(根据实体定制查询语句)
EFCore扩展Select方法(根据实体定制查询语句) 通常用操作数据库的时候查询返回的字段是跟 我们的定义的实体是不一致的,所以往往针对UI或者接口层创建大量的Model, 而且需要手动对应字段 ...
- c# linq查询语句详细使用介绍
本文介绍Linq的使用方法 linq介绍 LINQ只不过是实现IEnumerable和IQueryable接口的类的扩展方法的集合. LINQ可以查询IEnumerable集合或者IQueryable ...
随机推荐
- 用jmeter进行接口测试(2)
1.jmeter配置元件之HTTP信息头管理器使用 右击线程组-[添加]-[HTTP信息头管理器] 是打发 Jmeter请求元件之参数化txt
- java高并发核心要点|系列5|CPU内存伪共享
上节提到的:伪共享,今天我们来说说. 那什么是伪共享呢? 这得从CPU的缓存结构说起.以下如图,CPU一般来说是有三级缓存,1 级,2级,3级,越上面的,越靠近CPU的,速度越快,成本也越高.也就是说 ...
- 如何创建DLL,以及注入DLL
为了防止忘记,特记下 DLL的创建,在VS2017中选择dll的创建 // dllmain.cpp : Defines the entry point for the DLL application. ...
- SpringMVC 向页面传值-Map、Model和ModelMap
除了使用ModelAndView方式外.还可以使用Map.Model和ModelMap来向前台页面传值 使用后面3种方式,都是在方法参数中,指定一个该类型的参数.例如: Java代码 @Request ...
- springboot返回html和jsp
一.返回html (1)添加maven依赖 <dependency> <groupId>org.springframework.boot</groupId> ...
- 创建一个jFinal项目
最近在做微信开发,于是用到了jfinal. 做一下解释: JFinal 是基于 Java 语言的极速 WEB + ORM 开发框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩 ...
- java——HttpClient 代理模式发送Http Https
在setProxy()方法中设置代理IP后可以将url中的域名换成这个代理IP. http很简单,但是https这样会报错. 问题:如何使用代理发送https请求? 客户端发送https请求之前会先向 ...
- ansible-乱
工作机制:ssh 无客户端 工作方式: 1,CMDB 2,公有云私有云API 3,使用ad-hoc 4,ansible-playbook ansible 执行命令,底层调用传输连接模块,将命令或文件传 ...
- (51)LINUX应用编程和网络编程之六Linux高级IO
3.6.1.非阻塞IO 3.6.1.1.阻塞与非阻塞 阻塞:阻塞具有很多优势(是linux系统的默认设置),单路IO的时候使用阻塞式IO没有降低CPU的性能 补充:阻塞/非阻塞, 它们是程序在等待消息 ...
- 一个优雅的图片裁剪插件vue-cropper
github: https://github.com/xyxiao001/vue-cropper