Why does the 'equals' operator in LINQ join?

Why is the link not simply related to using the == operator in joins if t can use it in the 'where' clause?

+5
source share
2 answers

Two sides of equality in a join are considered as two separate lambda expressions that generate keys for 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 keyword equals makes it unimportant when one lambda ends and another begins. For the where clause, on the other hand, there is one lambda expression that determines whether each element matches:

from prod in products
where prod.CategoryID == 1

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

Theoretically, unions could be implemented with a single lambda like

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 });

, , LINQ - , .

+10

, , () . , equals, 2 .

The Moth.

+6

All Articles