Joining and grouping

There are two extension methods for joining and grouping:

  • Join: This method has four parameters: the sequence that you want to join with, the property or properties on the left sequence to match on, the property or properties on the right sequence to match on, and a projection
  • GroupJoin: This method has the same parameters, but it combines the matches into a group object with a Key property for the matching value and an IEnumerable<T> type for the multiple matches

In the Main method, write the following statements:

// create two sequences that we want to join together 
var categories = db.Categories.Select(    c => new { c.CategoryID, c.CategoryName }).ToArray(); 
 
var products = db.Products.Select( p => new { p.ProductID, ...

Get C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.