Part 18 GroupBy in LINQ
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/07/part-18-groupby-in-linq.html
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1
Slides
http://csharp-video-tutorials.blogspot.com/2014/07/part-18-groupby-in-linq_26.html
LINQ Tutorial - All Text Articles & Slides
http://csharp-video-tutorials.blogspot.com/2014/07/linq-tutorial.html
LINQ Tutorial Playlist
https://www.youtube.com/playlist?list=PL6n9fhu94yhWi8K02Eqxp3Xyh_OmQ0Rp6
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
GroupBy operator belong to Grouping Operators category. This operator takes a flat sequence of items, organize that sequence into groups (IGrouping[K,V]) based on a specific key and return groups of sequences.
In short, GroupBy creates and returns a sequence of IGrouping[K,V]
Example 1: Get Employee Count By Department
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department;
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Count());
}
Example 2: Get Employee Count By Department and also each employee and department name
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department;
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Count());
Console.WriteLine("----------");
foreach (var employee in group)
{
Console.WriteLine(employee.Name + "\t" + employee.Department);
}
Console.WriteLine(); Console.WriteLine();
}
Example 3: Get Employee Count By Department and also each employee and department name. Data should be sorted first by Department in ascending order and then by Employee Name in ascending order.
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department into eGroup
orderby eGroup.Key
select new { Key = eGroup.Key, Employees = eGroup.OrderBy(x =] x.Name) };
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Employees.Count());
Console.WriteLine("----------");
foreach (var employee in group.Employees)
{
Console.WriteLine(employee.Name + "\t" + employee.Department);
}
Console.WriteLine(); Console.WriteLine();
}
Видео Part 18 GroupBy in LINQ канала kudvenkat
http://csharp-video-tutorials.blogspot.com/2014/07/part-18-groupby-in-linq.html
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1
Slides
http://csharp-video-tutorials.blogspot.com/2014/07/part-18-groupby-in-linq_26.html
LINQ Tutorial - All Text Articles & Slides
http://csharp-video-tutorials.blogspot.com/2014/07/linq-tutorial.html
LINQ Tutorial Playlist
https://www.youtube.com/playlist?list=PL6n9fhu94yhWi8K02Eqxp3Xyh_OmQ0Rp6
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
GroupBy operator belong to Grouping Operators category. This operator takes a flat sequence of items, organize that sequence into groups (IGrouping[K,V]) based on a specific key and return groups of sequences.
In short, GroupBy creates and returns a sequence of IGrouping[K,V]
Example 1: Get Employee Count By Department
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department;
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Count());
}
Example 2: Get Employee Count By Department and also each employee and department name
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department;
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Count());
Console.WriteLine("----------");
foreach (var employee in group)
{
Console.WriteLine(employee.Name + "\t" + employee.Department);
}
Console.WriteLine(); Console.WriteLine();
}
Example 3: Get Employee Count By Department and also each employee and department name. Data should be sorted first by Department in ascending order and then by Employee Name in ascending order.
var employeeGroup = from employee in Employee.GetAllEmployees()
group employee by employee.Department into eGroup
orderby eGroup.Key
select new { Key = eGroup.Key, Employees = eGroup.OrderBy(x =] x.Name) };
foreach (var group in employeeGroup)
{
Console.WriteLine("{0} - {1}", group.Key, group.Employees.Count());
Console.WriteLine("----------");
foreach (var employee in group.Employees)
{
Console.WriteLine(employee.Name + "\t" + employee.Department);
}
Console.WriteLine(); Console.WriteLine();
}
Видео Part 18 GroupBy in LINQ канала kudvenkat
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Part 19 Group by multiple keys in linq](https://i.ytimg.com/vi/cH7ZV98zkpU/default.jpg)
![LINQ in C#.Net made easy! - PART 2 | OrderBy | ThenBy | GroupBy](https://i.ytimg.com/vi/Ftn9zYygBDw/default.jpg)
![C# Essentials: Linq for Lists - Sorting, Filtering, and Aggregating Lists Easily](https://i.ytimg.com/vi/yClSNQdVD7g/default.jpg)
![](https://i.ytimg.com/vi/4gUr69pKbxM/default.jpg)
![LINQ Join and Group](https://i.ytimg.com/vi/W5L2_wXj6gw/default.jpg)
![](https://i.ytimg.com/vi/Iae0pfVrZ1o/default.jpg)
![Part 17 AsEnumerable and AsQueryable in LINQ](https://i.ytimg.com/vi/zGug_IYlNts/default.jpg)
![Practical C# - SelectMany in LINQ](https://i.ytimg.com/vi/FrXwTbV9Do4/default.jpg)
![Part 16 Cast and OfType operators in LINQ](https://i.ytimg.com/vi/8LGSg6MFg3A/default.jpg)
![Shay Rojansky - How Entity Framework translates LINQ all the way to SQL - Dotnetos Conference 2019](https://i.ytimg.com/vi/r69ZxXgOIK4/default.jpg)
![.NET 6 EF Core 🚀 Load Related Data with Include(), ThenInclude() & AutoInclude()](https://i.ytimg.com/vi/7HuOivcr6Mg/default.jpg)
![C# Events and Delegates Made Simple | Mosh](https://i.ytimg.com/vi/jQgwEsJISy0/default.jpg)
![Part 23 Difference between group join and inner join in linq](https://i.ytimg.com/vi/l8ATBgdeg80/default.jpg)
![5 New Features in C# 9 (not including Records)](https://i.ytimg.com/vi/f0YeVirKPfw/default.jpg)
![Part 8 SelectMany Operator in LINQ](https://i.ytimg.com/vi/zQnkh8GpUQU/default.jpg)
![Part 21 Group Join in LINQ](https://i.ytimg.com/vi/Da3akpqjaR4/default.jpg)
![(#12) OrderBy in LINQ | LINQ tutorial for beginners](https://i.ytimg.com/vi/Ww4aeXxKibY/default.jpg)
![Part 11 Ordering Operators in LINQ II](https://i.ytimg.com/vi/PkgHCDI9mK0/default.jpg)
![SSRS Reports Training - Grouping in Reports, Adding Summary Calculations](https://i.ytimg.com/vi/VopbE17pPCc/default.jpg)
![Part 15 Conversion Operators in LINQ](https://i.ytimg.com/vi/an_bpgQ7y9w/default.jpg)