How to use LINQ multiple joins

Web developers use LINQ join clause when they want to associate elements from different source sequences that have no direct relationship in the object model. For example, an electronic devices distributor might have a list of suppliers of a certain product, and a list of buyers. A join clause can be used, for example, to create a list of the suppliers and buyers of that product who are all in the same specified region

A join clause takes two source sequences as input. The elements in each sequence must either be or contain a property that can be compared to a corresponding property in the other sequence. The join clause compares the specified keys for equality by using the special equals keyword. All joins performed by the join clause are equijoins. The shape of the output of a join clause depends on the specific type of join Web developers are performing.

Any number of join operations can be appended to each other to perform a multiple join. Each join clause in C# correlates a specified data source with the results of the previous join.

The following example creates three collections: a list of Student objects, a list of Album objects, and a list of Movie objects.

The first join clause in C# matches students and albums based on a Student object matching Book.Owner. It returns a sequence of anonymous types that contain the Student object and Album.Title.

The second join clause in C# correlates the anonymous types returned by the first join with Movie objects in the supplied list of movies, based on a composite key that consists of the Owner property of type Student, and the first letter of the album’s title. It returns a sequence of anonymous types that contain the Album.Title and Movie.Title properties from each matching pair. Because this is an inner join, only those objects from the first data source that have a match in the second data source are returned.