Загрузка страницы

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
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
27 июля 2014 г. 0:43:06
00:10:28
Яндекс.Метрика