class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public int DeptId { get; set; }
}
class Dept
{
public int DeptId { get; set; }
public string DeptName { get; set; }
}
List<Dept> dept = new List<Dept>();
List<Employee> emp = new List<Employee>();
dept.AddRange(new Dept[]
{
new Dept{ DeptId=1, DeptName="IT" },
new Dept{ DeptId=2, DeptName="Engineering" }
});
emp.AddRange(new Employee[]
{
new Employee{EmployeeID = 1, DeptId = 1, EmployeeName="Sohail"},
new Employee{EmployeeID = 2, DeptId = 1, EmployeeName="Zeeshan"},
new Employee{EmployeeID = 3, DeptId = 2, EmployeeName="Zubair"},
});
emp.Join(dept, empRow => empRow.DeptId, deptRow => deptRow.DeptId, (selectEmpRow, selectDeptRow) =>
new
{
EmpId = selectEmpRow.EmployeeID,
EmpName = selectEmpRow.EmployeeName,
DeptName = selectDeptRow.DeptName
})
.ToList()
.ForEach(_ => { Console.WriteLine("{0} {1} {2}", _.EmpId, _.EmpName, _.DeptName); });
This blog contains information related to .Net programs, Dynamics & many more...
Showing posts with label Join C#. Show all posts
Showing posts with label Join C#. Show all posts
Thursday, December 27, 2012
LINQ Join Query
Subscribe to:
Posts (Atom)