What is the difference between left and right sides of equalities in linq connection

When making a connection in Linq, for example

from c in customers join x in somelistofcustomers on x.Id equals c.Id

you will get an error

x is not in the scope on the left side of the equal equation. Consider replacing expressions on either side of "equals"

It’s simple enough to do, but I would like to explain why x is not in the scope on the left side, but somehow is in the area on the right side of equals

+5
source share
2 answers

This is due to how LINQ extends the compiler into the main extension methods.

Your request is translated into:

customers.Join(somelistofcustomers, c => x.Id, x => c.Id, (c, x) => ...)

- c => x.Id x => c.Id, , . LINQ - , , .

+8

,

from identifier in {outer-sequence} 
join identifier2 in {inner-sequence} 
on {outer-key-selector} equals {inner-key-selector}

identifier {outer-key-selector} , identifier2 {inner-key-selector} - , .

+2

All Articles