CODEDIGEST InstallShield
Home Articles CodeDigest Tutorials InstallShield FAQs
Skip Navigation LinksHome » CodeDigest » How to create a simple JOIN LINQ query to fetch data from 2 entities?   You are not logged in.
Search
 

Sponsors
InstallShield
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
How to create a simple JOIN LINQ query to fetch data from 2 entities?
How to create a simple JOIN LINQ query to fetch data from 2 entities?
Submitted By Satheesh Babu
On 6/14/2009 7:12:27 AM
Tags: CodeDigest,LINQ  

How to create a simple JOIN LINQ query to fetch data from 2 entities?

The below LINQ query will retrieve the Employee details by joining (inner join) Department table to fetch the DepartmentName using the DeptID in Employee table.
     
  EmployeeInfoDataContext dbEmp = new EmployeeInfoDataContext();
        var query = from emp in dbEmp.Employees
                    join dept in dbEmp.Departments
                        on emp.DeptID equals dept.DeptID
                    select new
                    {
                        EmpID = emp.EmpID,
                        EmpName = emp.EmpName,
                        Age = emp.Age,
                        Address = emp.Address,
                        DeptName = dept.DepartmentName
                    };

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!