Linq SelectMany Examples – C# Programming Example
Collection Linq List

Linq SelectMany Examples

The SelectMany operator creates a one-to-many output projection sequence over an input sequence. SelectMany will return 0 or more output elements for every input element.

We’ll need some classses which have some properies. In the posts on LINQ we take the following collections for tutorial

Create the following classes:

 

Create example data for queries:

 

Example 1: Lets look this example, we can simply select details of author from books. Because “Book class” has Author property

 

Example 2: But we can’t select directly book’s name from author. Therefore we must use multiple tables with where clause.
Linq provides SelectMany Method that the SelectMany operator creates a one-to-many output projection sequence over an input sequence.

Example 4: Select books with details(Author’s name and lastname)

 

 

 

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: