C# Interview Question #49

What is Join() in LINQ?

LINQ & Querying Mid-Level Intermediate

Quick Interview Answer

Join combines elements from two sequences using matching keys, similar to an SQL INNER JOIN.

Detailed Explanation

Join combines elements from two sequences using matching keys, similar to an SQL INNER JOIN.

LINQ also supports relationship-style querying through navigation properties in Entity Framework Core. For more complex joins, query syntax can sometimes be easier to read.

A left outer join can be expressed using GroupJoin and DefaultIfEmpty, although EF Core navigation properties often provide a cleaner model when relationships are configured correctly.

Code Example

var result = products.Join(
    categories,
    p => p.CategoryId,
    c => c.Id,
    (p, c) => new
    {
        Product = p.Name,
        Category = c.Name
    });