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 ...
随机推荐
- websocket之拨云见雾
websocket是基于http相应的特性弥补其不足(就是个socket,不再是一次请求一次相应) 但缺点就是只有在版本较高的浏览器才支持websocket. 浏览器: <script type ...
- LeNet-5模型的keras实现
import keras from keras.models import Sequential from keras.layers import Input,Dense,Activation,Con ...
- javaweb 项目编码格式设置
- SpringMVC @ModelAttribute详解
被@ModelAttribute注释的方法会在此controller每个方法执行前被执行,因此对于一个controller映射多个URL的用法来说,要谨慎使用. 我们编写控制器代码时,会将保存方法独立 ...
- SSH加密传输
数据传输安全的要满足的要求: (1)消息的发送方能够确定消息只有预期的接收方可以解密(不保证第三方无法获得,但保证第三方无法解密) (2)消息的接收方可以确定消息是由谁发送的(消息的接收方可以确定消息 ...
- python技巧31[移植python2.x到3.x]
我们都知道python从2.x升级到3.x的过程中有一些不兼容的改动,但是有时还我们不得不将2.x的程序升级到3.x. 主要不兼容如下图: 移植过程: 1) 确保存在的代码有足够的测试覆盖.从2.x到 ...
- Charles在windows上抓取本地python的 request请求
首先打开charles,在Proxy中打开Windows Proxy,这样才能抓取本地请求 python代码中报错Caused by SSLError(SSLError(1, '[SSL: CERTI ...
- C++ std::vector 总结笔记
Initialization #include<iostream> #include<vector> using namespace std; int main() { vec ...
- Fiddler的工作原理与主菜单介绍(一)
1.简介: 官网:https://www.telerik.com/fiddler Fiddler是比较好用的web代理调试工具之一,它能记录并检查所有客户端与服务端的HTTP/HTTPS请求,能够设置 ...
- Idea中Springboot热部署无效解决方法
仅适用IDEA中,eclipse中不需要设置 一.开启idea自动make功能 1 - Enable Automake when the application is running PRESS: C ...