I have the following lambda expression:
string queryToken = queryTokens.Last();
var result = from locationAddress in locations
let tokens = GetLetterTokens(locationAddress.Name)
let distance = (from token in tokens
where token.Contains(queryToken, StringComparison.OrdinalIgnoreCase)
select token.Length - queryToken.Length).Min()
orderby distance
select new
{
LocationAddress = locationAddress,
LocationDistance = distance,
};
It doesn’t matter what it’s written for. Sometimes when counting distance, there are no tokens containing queryToken, so .Min() couldn’t be returned. How to skip these cases? I don’t want to add them into result variable.
Sounds like you just want:
Alternatively, just filter when you select the tokens, and then check whether any exist: