linq 学习笔记之 Linq基本子句
1 from 子句
一个linq表达式,必须是以from子句开头。
var value=from v in values where v.indexof("it")>-1 select v
2复合from子句(多重嵌套查询:便于自己理解)
var query=from a in aa
from b in a.b where b.indexof("2")>-1 select a
3多个from子句(结果交叉链接)
var query=from a in aa where a.age>20
from b in bb where b.age>17
select new{ aa, bb}
4 where 子语句
5 into子句
into子句作为一个临时的标识符,用于group select jion 语句中
var query=from a in alist group by a.name.Substring(0,1) into anamelist orderby anamelist.key descending select anamelist;
6let 子句(let 可以设一个变量)
var query=from a in alist let g=a.age where g>12 select alist;
7 join子语句
var query= from a in alist join b in blist on a.name equals b.name select new{Name=a.name ,Title=b.name}