Why does join not work with let clause storing IEnumerable

Viewed 178

The following code works fine in Linq, when I join the tables using the where clause

var result =
    from dist in distributors
    let mainDistributorStates = new List<string> {"TX", "OR"}
    from mdist in mainDistributorStates 
    where dist.State == mdist
    select dist; 

But the following doesn't, showing the comiler error

mainDistributorStates does not exist in the current context.

var result =
    from dist in distributors
    let mainDistributorStates = new List<string> {"TX", "OR"}
    join mdist in mainDistributorStates 
     on dist.State equals mdist
    select dist; 

Based on the documentation:

In a query expression, it is sometimes useful to store the result of a sub-expression in order to use it in subsequent clauses.

Since the let clause stores an IEnumerable, why can't it be used like any other data source in linq?

0 Answers
Related