//LINQ查询集合对象
//students对象是泛型集合,不能为null,否则抛异常
var theStudents = from s in students
where s.ID > 115 && s.FirstName.Contains("a")
//where s.ExamScores[0] == 99
select s;
Response.Write(theStudents.Count().ToString() + "<br />");
foreach (var s in theStudents)
{
Response.Write(s.FirstName + " " + s.ID.ToString() + "<br />");
}
var lstRst = from l in lstLangset
join f in LstFormName on l.FormName equals f.FormCode
group f by new { f.FormPath, f.FormName } into g
select new LanguageInfo { UIPath = g.Key.FormPath, UIName = g.Key.FormName, LangCount = g.Count() };
1、左连接:
var LeftJoin = from emp in ListOfEmployees
join dept in ListOfDepartment
on emp.DeptID equals dept.ID into JoinedEmpDept
from dept in JoinedEmpDept.DefaultIfEmpty()
select new
{
EmployeeName = emp.Name,
DepartmentName = dept != null ? dept.Name : null
};
2、右连接:
var RightJoin = from dept in ListOfDepartment
join employee in ListOfEmployees
on dept.ID equals employee.DeptID into joinDeptEmp
from employee in joinDeptEmp.DefaultIfEmpty()
select new
{
EmployeeName = employee != null ? employee.Name : null,
DepartmentName = dept.Name
};
3、内连接: