Part 21 Group Join in LINQ04:33

  • 0
Published on May 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
Inner Join
Left Outer Join
Cross Join

In this video, we will discuss Group Join. Group Join produces hierarchical data structures. Each element from the first collection is paired with a set of correlated elements from the second collection.

Let us understand Group Join with an example. A Department may have ZERO or MORE employees.

Example 1: Group employees by Department.
var employeesByDepartment = Department.GetAllDepartments()
.GroupJoin(Employee.GetAllEmployees(),
d =] d.ID,
e =] e.DepartmentID,
(department, employees) =] new
{
Department = department,
Employees = employees
});

foreach (var department in employeesByDepartment)
{
Console.WriteLine(department.Department.Name);
foreach (var employee in department.Employees)
{
Console.WriteLine(” ” + employee.Name);
}
Console.WriteLine();
}

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

Please note: Group Join uses the join operator and the into keyword to group the results of the join.

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!"