linq 日常关键字使用
1.from
var scoreQuery = from student in students
from score in student.Scores
where score > 90
select new { Last = student.LastName, score };
2.where
var queryLowNums3 =
from num in numbers
where num < 5
where num % 2 == 0
select num;
3.select
var studentQuery7 =
from student in app.students
where student.ID > 111
select new { student.First, student.Last };
4.group
var studentQuery =
from student in students
let avg = (int)student.Scores.Average()
group student by (avg == 0 ? 0 : avg / 10) into g
orderby g.Key
select g;
5.into
var wordGroups1 =
from w in words
group w by w[0] into fruitGroup
where fruitGroup.Count() >= 2
select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };
6.orderby
var sortedGroups =
from student in students
orderby student.Last, student.First
group student by student.Last[0] into newGroup
orderby newGroup.Key
select newGroup;
7.join
var innerJoinQuery =
from category in categories
join prod in products on category.ID equals prod.CategoryID
select new { ProductName = prod.Name, Category = category.Name }; //produces flat sequence
var innerGroupJoinQuery =
from category in categories
join prod in products on category.ID equals prod.CategoryID into prodGroup
select new { CategoryName = category.Name, Products = prodGroup };
8.ascending
IEnumerable<string> sortAscendingQuery =
from vegetable in vegetables
orderby vegetable ascending
select vegetable;
9.descending
IEnumerable<string> sortDescendingQuery =
from vegetable in vegetables
orderby vegetable descending
select vegetable;
10.on
var innerJoinQuery =
from category in categories
join prod in products on category.ID equals prod.CategoryID
select new { ProductName = prod.Name, Category = category.Name };
11.equals
var innerJoinQuery =
from category in categories
join prod in products on category.ID equals prod.CategoryID
select new { ProductName = prod.Name, Category = category.Name };
12.by
var query = from student in students
group student by student.LastName[0];
linq 日常关键字使用的更多相关文章
- Linq中关键字的作用及用法
Linq中关键字的作用及用法 1.All:确定序列中的所有元素是否都满足条件.如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true:否则为 false. Demo: 此示例使用 ...
- [LINQ]查询关键字
摘自https://msdn.microsoft.com/zh-cn/library/bb310804.aspx,方便以后翻阅. from子句 查询表达式必须以 from 子句开头.另外,查询表达式还 ...
- Linq之关键字基本查询
子句 说明 from 指定数据源和范围变量(类似于迭代变量). where 根据一个或多个由逻辑"与"和逻辑"或"运算符(&& 或 ||)分隔的 ...
- 日常关键字:定时关机、该任务映像已损坏或已篡改.(0x80041321)、ChaZD生词同步扇贝
我在床上用chinanet网络慢得简直令人发指,12B/S.是的你没有看错,这是我最常看到的网速.但是我最近发现电脑联网开出一个WiFi,在床上用手机上网时,网速会一点提升,可达到1KB/S(⊙﹏⊙) ...
- LINQ日常使用记录
1.公司一位美女程序媛写的 2.技术总监提供(来自互联网) var query = from f in db.TField join fw in db.TFieldWel on f.emp_no eq ...
- 通过orderby关键字,LINQ可以实现升序和降序排序。LINQ还支持次要排序。
通过orderby关键字,LINQ可以实现升序和降序排序.LINQ还支持次要排序. LINQ默认的排序是升序排序,如果你想使用降序排序,就要使用descending关键字. static void M ...
- 对于Linq关键字和await,async异步关键字的扩展使用
最近在看neuecc大佬写的一些库:https://neuecc.medium.com/,其中对await,async以及linq一些关键字实现了自定义化使用, 使其不需要引用对应命名空间,不需要多线 ...
- Linq的查询操作符
Linq有表达式语法和调用方法的语法.两者是可以结合使用,通常情况下也都是结合使用.表达式语法看上去比较清晰而调用方法的语法实现的功能更多,在此文章中介绍的是表达式语法.方法语法可以看System.L ...
- .Net 如何实现 LINQ~
本文内容 引入 实现 LINQ 的两个前提 扩展方法 λ 表达式 LINQ 参考资料 本文说明 LINQ 是如何实现的,知道这点,才能更好地使用它~ 如果你刚接触 LINQ,那么可能不会那么快就理解. ...
随机推荐
- WPF 之 实现TextBox输入文字后自动弹出数据(类似百度的输入框)
1.添加一个数据实体类 AutoCompleteEntry,如下: using System; using System.Collections.Generic; using System.Linq; ...
- 在C#中利用SharpZipLib进行文件的压缩和解压缩收藏
我在做项目的时候需要将文件进行压缩和解压缩,于是就从http://www.icsharpcode.net(http://www.icsharpcode.net/OpenSource/SharpZipL ...
- Conversions
Problem Description Conversion between the metric and English measurement systems is relatively simp ...
- JavaScript组成
JavaScript由ECMAScript,Dom,Bom三部分组成. ECMAScript是一种由Ecma国际(前身为欧洲计算机制造商协会,英文名称是European Computer Manufa ...
- android 内存优化以及性能优化相关问题
最近做一个android 的应用程序 总是出现内存高 和cpu高的问题困扰了好多天. 下面为自己从网上总结的和自己找到的问题. 1. WebView 控件: 使用了 WebView 控件一定要注意清 ...
- 将Winform程序快速转换为在浏览器中运行的程序
http://www.codeproject.com/Articles/31429/Embedding-a-NET-WinForms-Application-in-an-Interne 详见以上文章. ...
- cent os 6 安装 nginx
cent os 6 默认的库是没有nginx的,所以直接 yum install nginx不行. 解决办法: $ wget http://nginx.org/packages/centos/6/no ...
- javaweb学习总结二十六(response对象的用法二 下载文件)
一:浏览器打开服务器上的文件 1:读取服务器上面的资源,如果在web层,可以直接使用servletContext,如果在非web层 可以使用类加载器读取文件 2:向浏览器写数据,实际上是把数据封装到r ...
- IIs站点的建立
控制面板——管理工具——Internet信息服务管理器 首先应设置的文件权限:System 和 admin 程序池:4.0 编辑权限:iis apppool\名称 身份验证:匿名身份——应用程序池标识
- Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...