Reputation: 1514
I know that there is let operator in linq query syntax. It is useful to store the result of a sub-expression in order to use it in subsequent clauses.
But I prefer work with linq lambda syntax. When I work with a lot of joins i get chain of objects (which represent each level of joins ie: `
s.secondJoin.firstJoin.dd.DataType`
I would like to set some sub result in variable and use it for more convinient work in the following ie:
let joinResult = s.secondJoin.firstJoin
and after
joinResult.dd.DataType
Q: Is it possible in linq lambda syntax?
Upvotes: 0
Views: 2227
Reputation: 586
Equivalent to let
in lambda syntax is Select
to create an anonymous type, for example:
items.Select(s => new
{
s = s,
joinResult = s.secondJoin.firstJoin
})
After this you can use both s
and joinResult
as you could with let
in query syntax.
Upvotes: 2