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,那么可能不会那么快就理解. ...
随机推荐
- A标签使用javascript:伪协议
一.前言 今天,遇到一个别人挖的坑,问题是这样的. 做了一个列表页,可以筛选数据,有很多筛条件.主要是有input复选框和<a>标签两种.如图: 其中房价的筛选条件使用<a>标 ...
- C# mvc--EF中查询的本质
UI层我直接用了窗体程序. 好了 不罗嗦 直接上代码…… private void button1_Click(object sender, EventArgs e) { //1.0创建EF上下文容器 ...
- 【源码】初探C#爬虫,持续更新中。。。
最近看到园子里有人用python做的爬虫软件并且上传的源码,苦于不懂python,便想着用C#也实现一个简易的爬虫软件.于是昨晚花了一个多小时的时间实现了一个简单的爬虫软件,功能十分简单,但是觉 ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
- 开启AsyncTask从网络加载图片
/*AsyncTask 异步任务即做一些简单的异步处理 :是handle与线程池的封装 * 第一个泛型:参数类型泛型 * 第二个泛型:更新进度泛型 * 第三个泛型:onProgressUpdate的返 ...
- 对C++/CLR的一些评价
我以后要是再用这东西,我自砍双手
- vb6.0如何让窗体跟随鼠标运动
首先将form的boderstyle属性设为0 Dim movesScreen As Boolean Dim mousX As Integer Dim mousY As Integer Dim cur ...
- CentOS7,Firewalld防火墙使用方法
查看防火墙状态 systemctl status firewalld.service 启动firewall systemctl stop firewalld.service 停止firewall sy ...
- uclibc,eglibc,glibc之间的区别和联系
http://bbs.chinaunix.net/thread-3762882-1-1.html 1.Glibc glibc = GNU C Library 是GNU项(GNU Project)目,所 ...
- SqlServer知识总结
SqlServer查询表的列数 select count(*) from sysobjects a join syscolumns b on a.id=b.id where a.name='表名' 在 ...