Part 8 SelectMany Operator in LINQ
Text version of the video
http://csharp-video-tutorials.blogspot.com/2014/07/part-8-selectmany-operator-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-8-selectmany-operator-in-linq_10.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
SelectMany Operator belong to Projection Operators category. It is used to project each element of a sequence to an IEnumerable[T] and flattens the resulting sequences into one sequence.
Example 1: Projects all subject strings of a given a student to an IEnumerable[string]. In this example since we have 4 students, there will be 4 IEnumerable[string] sequences, which are then flattened to form a single sequence i.e a single IEnumerable[string] sequence.
IEnumerable[string] allSubjects = Student.GetAllStudetns().SelectMany(s =] s.Subjects);
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 2: Rewrite Example1 using SQL like syntax. When using SQL like syntax style, we don't use SelectMany, instead we will have an additional from clause, which will get it's data from the results of the first from clause.
IEnumerable[string] allSubjects = from student in Student.GetAllStudetns()
from subject in student.Subjects
select subject;
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 3: Projects each string to an IEnumerable[char]. In this example since we have 2 strings, there will be 2 IEnumerable[char] sequences, which are then flattened to form a single sequence i.e a single IEnumerable[char] sequence.
string[] stringArray =
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0123456789"
};
IEnumerable[char] result = stringArray.SelectMany(s =] s);
foreach (char c in result)
{
Console.WriteLine(c);
}
Example 4: Rewrite Example3 using SQL like syntax.
string[] stringArray =
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0123456789"
};
IEnumerable[char] result = from s in stringArray
from c in s
select c;
foreach (char c in result)
{
Console.WriteLine(c);
}
Example 5: Selects only the distinct subjects
IEnumerable[string] allSubjects = Student.GetAllStudetns().SelectMany(s =] s.Subjects).Distinct();
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 6: Rewrite Example 5 using SQL like syntax.
IEnumerable[string] allSubjects = (from student in Student.GetAllStudetns()
from subject in student.Subjects
select subject).Distinct();
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 7: Selects student name along with all the subjects
var result = Student.GetAllStudetns().SelectMany(s =] s.Subjects, (student, subject) =]
new { StudentName = student.Name, Subject = subject });
foreach (var v in result)
{
Console.WriteLine(v.StudentName + " - " + v.Subject);
}
Example 8: Rewrite Example 7 using SQL like syntax.
var result = from student in Student.GetAllStudetns()
from subject in student.Subjects
select new { StudnetName = student.Name, Subject = subject };
foreach (var v in result)
{
Console.WriteLine(v.StudnetName + " - " + v.Subject);
}
Видео Part 8 SelectMany Operator in LINQ канала kudvenkat
http://csharp-video-tutorials.blogspot.com/2014/07/part-8-selectmany-operator-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-8-selectmany-operator-in-linq_10.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
SelectMany Operator belong to Projection Operators category. It is used to project each element of a sequence to an IEnumerable[T] and flattens the resulting sequences into one sequence.
Example 1: Projects all subject strings of a given a student to an IEnumerable[string]. In this example since we have 4 students, there will be 4 IEnumerable[string] sequences, which are then flattened to form a single sequence i.e a single IEnumerable[string] sequence.
IEnumerable[string] allSubjects = Student.GetAllStudetns().SelectMany(s =] s.Subjects);
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 2: Rewrite Example1 using SQL like syntax. When using SQL like syntax style, we don't use SelectMany, instead we will have an additional from clause, which will get it's data from the results of the first from clause.
IEnumerable[string] allSubjects = from student in Student.GetAllStudetns()
from subject in student.Subjects
select subject;
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 3: Projects each string to an IEnumerable[char]. In this example since we have 2 strings, there will be 2 IEnumerable[char] sequences, which are then flattened to form a single sequence i.e a single IEnumerable[char] sequence.
string[] stringArray =
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0123456789"
};
IEnumerable[char] result = stringArray.SelectMany(s =] s);
foreach (char c in result)
{
Console.WriteLine(c);
}
Example 4: Rewrite Example3 using SQL like syntax.
string[] stringArray =
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0123456789"
};
IEnumerable[char] result = from s in stringArray
from c in s
select c;
foreach (char c in result)
{
Console.WriteLine(c);
}
Example 5: Selects only the distinct subjects
IEnumerable[string] allSubjects = Student.GetAllStudetns().SelectMany(s =] s.Subjects).Distinct();
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 6: Rewrite Example 5 using SQL like syntax.
IEnumerable[string] allSubjects = (from student in Student.GetAllStudetns()
from subject in student.Subjects
select subject).Distinct();
foreach (string subject in allSubjects)
{
Console.WriteLine(subject);
}
Example 7: Selects student name along with all the subjects
var result = Student.GetAllStudetns().SelectMany(s =] s.Subjects, (student, subject) =]
new { StudentName = student.Name, Subject = subject });
foreach (var v in result)
{
Console.WriteLine(v.StudentName + " - " + v.Subject);
}
Example 8: Rewrite Example 7 using SQL like syntax.
var result = from student in Student.GetAllStudetns()
from subject in student.Subjects
select new { StudnetName = student.Name, Subject = subject };
foreach (var v in result)
{
Console.WriteLine(v.StudnetName + " - " + v.Subject);
}
Видео Part 8 SelectMany Operator in LINQ канала kudvenkat
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Part 7 Projection Operators in LINQ](https://i.ytimg.com/vi/UHbjfJYRxjc/default.jpg)
![Part 9 Difference between Select and SelectMany in LINQ](https://i.ytimg.com/vi/9tgz3aVNblM/default.jpg)
![](https://i.ytimg.com/vi/4gUr69pKbxM/default.jpg)
![Part 17 AsEnumerable and AsQueryable in LINQ](https://i.ytimg.com/vi/zGug_IYlNts/default.jpg)
![Part 23 Difference between group join and inner join in linq](https://i.ytimg.com/vi/l8ATBgdeg80/default.jpg)
![Part 13 Implement paging using skip and take operators](https://i.ytimg.com/vi/neAEEMBUeME/default.jpg)
![LINQ in C#.Net made easy! - PART 3 : Joins in LINQ | Inner Join | Group Join | Left Outer Join](https://i.ytimg.com/vi/vAGnEdabFpM/default.jpg)
![](https://i.ytimg.com/vi/Iae0pfVrZ1o/default.jpg)
![Part 11 Ordering Operators in LINQ II](https://i.ytimg.com/vi/PkgHCDI9mK0/default.jpg)
![Configure ASP NET Core request processing pipeline](https://i.ytimg.com/vi/nt6anXAwfYI/default.jpg)
![Delegates in C# - A practical demonstration, including Action and Func](https://i.ytimg.com/vi/R8Blt5c-Vi4/default.jpg)
![IEnumerable 🆚 IEnumerator Interfaces in C#](https://i.ytimg.com/vi/VcAubtFBOdY/default.jpg)
![Part 28 Generation Operators in LINQ](https://i.ytimg.com/vi/mBnSc7GW01s/default.jpg)
![Entity Framework Best Practices - Should EFCore Be Your Data Access of Choice?](https://i.ytimg.com/vi/qkJ9keBmQWo/default.jpg)
![Part 12 Partitioning Operators in LINQ](https://i.ytimg.com/vi/YMhg6nDCAwA/default.jpg)
![Entity Framework Core Part 9 - The Fluent API](https://i.ytimg.com/vi/7M501P-23Jg/default.jpg)
![12.- LINQ para manipular y obtener objetos complejos con subconsultas | Curso de fundamentos de C#](https://i.ytimg.com/vi/r8Th2EYUVZY/default.jpg)
![Part 27 Union, Intersect and Except operators in LINQ](https://i.ytimg.com/vi/RplcRTcRXxM/default.jpg)
![What are Delegates? (C# Basics, Lambda, Action, Func)](https://i.ytimg.com/vi/3ZfwqWl-YI0/default.jpg)
![Part 24 Left Outer Join in LINQ](https://i.ytimg.com/vi/5K8jwrlKV8E/default.jpg)