LINQ Join, how to impose a condition

Suppose we have two lists ( Firstand Second)

Id  Value
1   A
2   B
3   C

Id  NewValue
1   a10
1   a21
1   a61
2   b71
2   b79
3   c40
3   c48
3   c55

I want to complete a connection request

from p in First
join c in Second on p.Id equals c.Id
select new { p.Value, c.NewValue }

But I also want to impose a condition on the numerical part NewValueto select the one that is greater than 40. Only a61, then b71, etc. How to change my connection request?

+4
source share
1 answer

You cannot do this in join, but add a sentence where:

from p in First
join c in Second on p.Id equals c.Id
where int.Parse(c.NewValue.Substring(1)) > 40
select new { p.Value, c.NewValue }

Please note that you can work with int.TryParseand make sure the parsing is complete.

+4
source

Source: https://habr.com/ru/post/1688593/


All Articles