c#Linq联合查询

        public void Test2()
{
var queryResult1 = from e in empArray
from l in empLevelArray
select new { e, l }; var queryResult2 = from e in empArray
from l in empLevelArray
where e.LevelNum == l.LevelNum
select new { e, l }; var queryResult3 = from e in empArray
from l in empLevelArray
orderby e.LevelNum,e.Name #进行排序,按照等级和姓名
where e.LevelNum == l.LevelNum
select new { e.Name, l.LevelName, l.Salary }; foreach (var item in queryResult1)
{
Console.WriteLine(item);
}
}

查询两个表中相似的部分,或者取各自的一部分。

联合查询同样会遇到排序和其他的表现形式:

        /// <summary>
/// 学习Join On 关键字
/// </summary>
public void Test4()
{
var queryResult = from e in empArray
join l in empLevelArray
on e.LevelNum equals l.LevelNum //连接条件
where e.LevelNum > && l.Salary >
select new { e.LevelNum, l.Salary };
foreach (var item in queryResult)
{
Console.WriteLine(item);
}
}
        /// <summary>
/// 学习gruop by 分组
/// </summary>
public void Test5()
{
var queryResult = from e in empArray
group e by e.LevelNum into g
select new { g.Key, counts = g.Count() };
foreach (var item in queryResult)
{
Console.WriteLine("级别:"+item.Key+" 个数:"+item.counts);
}
}
上一篇:SQL44 将id=5以及emp_no=10001的行数据替换成id=5以及emp_no=10005


下一篇:Git 代码管理工具