Linq子查询
来源:互联网 发布:python源码剖析 百度云 编辑:程序博客网 时间:2024/06/06 06:42
NorthwindEntities db = new NorthwindEntities();
//查找包含a并转换为大写
List<string> query = (from q in db.Customers select q.CompanyName).ToList();
//查询长度最短的
//利用类库中函数
var query1 = from q1 in query where q1.Length == query.Min(c => c.Length) select q1;
//注意:q1的作用范围已进入到子查询,所以子查询应重新声明变量
var query2 = from q1 in query where q1.Length == (from q2 in query orderby q2.Length select q2.Length).First() select q1;
var query3 = query.Where(q1 => q1.Length == query.OrderBy(q2 => q2.Length).Select(q2 => q2.Length).First());
//into字句:用于保存临时查询结果.注意,into后面已无法在接from字句了;
//之前的查询变量经过q1之后,则不可见.这个道理就和lambda中的变量一样,
//出了作用域,就无法使用了
List<Customers> queryInto = (from q in db.Customers
where q.CustomerID.Contains("aa")
select q
into q1
where q1.CustomerID.Length > 4
select q1).ToList();
//let字句:将一个查询字句作为临时表量
var queryLet = from q in query let xx = from qq in query where qq == "YOYOYO" select qq select q+"_"+xx.First();
foreach (var str in queryLet)
{
Console.WriteLine(str);
}
//int[] numbers = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //传统下的子查询做法
//var query55 = from num in numbers select num * (from n in numbers where n % 2 == 0 select n).Count();
//var query66 = from num in numbers let evenNumbers = from n in numbers where n % 2 == 0 select n select num * evenNumbers.Count();
//foreach (var item in query66) { Console.WriteLine(item); }
Console.ReadKey();
- linq子查询
- Linq子查询
- Linq to SQL 语法查询(子查询 & in操作 & join )
- 从 SQL 到 LINQ: 合并, TOP, 子查询 (Bill Horst)
- linq根据传入数据集合查询对应子级数据
- linq子查询--学习linq的资料和笔记(五)
- LINQ 查询
- Linq查询
- Linq查询
- LINQ查询
- Linq查询
- Linq 查询
- linq 查询
- Linq查询
- LINQ查询
- LinQ查询
- LINQ查询
- Linq查询
- similar to inotify on Windows
- 渴婴问题编程
- [Rqnoj-148][NOIP1999]回文数
- C语言的跨平台性及库的跨平台性研究
- Logistic regression 逻辑回归 概述
- Linq子查询
- IT职业分类
- 专家提突破计算机瓶颈新思路
- 【整理】约瑟夫问题的数学方法
- 十大最具增长潜力中国概念股:世纪佳缘居首
- SetWindowRgn函数
- python 使用django post提交时出现 CSRF verification failed. Request aborted.
- 计算机“瓶颈”浅析之处理器与显卡
- MySQL性能优化的最佳20+条经验