Part 22 Inner Join in LINQ04:33

  • 0
Published on August 31, 2017

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

The following are the different types of joins in LINQ
Group Join – Discussed in Part 21
Inner Join
Left Outer Join
Cross Join

In this video we will discuss implementing INNER JOIN in LINQ. If you have 2 collections, and when you perform an inner join, then only the matching elements between the 2 collections are included in the result set. Non – Matching elements are excluded from the result set.

Let us understand Inner Join with an example.

Example 1 : Join the Employees and Department collections and print all the Employees and their respective department names.
var employees = Employee.GetAllEmployees().Join(Department.GetAllDepartments(), e =] e.DepartmentID,
d =] d.ID, (employee, department) =] new
{
EmployeeName = employee.Name,
DepartmentName = department.Name
});

foreach (var employee in employees)
{
Console.WriteLine(employee.EmployeeName + “t” + employee.DepartmentName);
}

Output: Notice that, in the output we don’t have Andy record. This is because, Andy does not have a matching department in Department collection. So this is effectively an inner join.

Example 2 : Rewrite Example 1 using SQL like syntax.
var employees = from e in Employee.GetAllEmployees()
join d in Department.GetAllDepartments()
on e.DepartmentID equals d.ID
select new { EmployeeName = e.Name, DepartmentName = d.Name };

foreach (var employee in employees)
{
Console.WriteLine(employee.EmployeeName + “t” + employee.DepartmentName);
}

Tags:, , ,

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

depo 25 bonus 25

https://parfumschristianblanc.com/

https://www.barplate.com/wp-includes/js/qris/

https://hotmusic507.org/

Enjoyed this video?
"No Thanks. Please Close This Box!"