Why the 'equals' operator in LINQ joins?

.net, linq

Solution

The two sides of the equality in a join are treated as two separate lambda expressions which generate the keys for the two sequences.

from category in categories
join prod in products on category.ID equals prod.CategoryID

categories.Join(products,
                category => category.ID,
                prod => prod.CategoryID,
                (category, prod) => new { Category = category, Product=prod });

Using the equals keyword makes it unabmiguous where one lambda ends and the other starts. For a where clause, on the other hand, there's a single lambda expression which decides whether each item matches:

from prod in products
where prod.CategoryID == 1

products.Where( prod => prod.CategoryID == 1 )

In theory, joins could have been implemented with a single lambda as

from category in categories
join prod in products on category.ID == prod.CategoryID

categories.Join(products,
                (category, prod) => category.ID == prod.CategoryID,
                (category, prod) => new { Category = category, Product=prod });

However, by computing two keys and doing the comparison itself, LINQ can use hash tables to compute the join more efficiently than if it had to execute an arbitrary comparison for every pair of elements.

Problem

Why doesn't link simply use the == operator in joins if t can use it in a 'where' clause?

Original source