C# Tutorials:Lambda Expression using Join?

Lambda Expression is one of the new feature in .Net framework from 3.5 version

Step 1:
Create a Web Application and add a web form.To the web form add a grid view:



Step 2:
Add a DBML add drag and drop your two tables.

Step 3:
Add a BO class and write the following code:

public IQueryable Demo()
{
DataClassesDataContext dc = new DataClassesDataContext();
{

var qry1 = dc.Departments.Join(dc.Employees, d1 => d1.PKDeptId,
e1 => e1.PKEmpId,
(d1, e1) => new {EmpId=e1.PKEmpId, EmpName = e1.EmpName,
EmpSalary = e1.EmpSalary,FkDeptId=e1.FKDeptId,
DeptId=d1.PKDeptId, DeptName = d1.DeptName, Location = d1.Location });
return qry1;
}
}
Step 4:

Add the following code in the Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
gvEmpDept.DataSource = new BO().Demo();
gvEmpDept.DataBind();
}

OutPut:


For more Information on Linq and Linq Examples Click Here

Comments