假设我们有两个列表(First
和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
我想执行联接查询
from p in First
join c in Second on p.Id equals c.Id
select new { p.Value, c.NewValue }
但是我也想在NewValue
的数字部分施加条件,选择大于40的条件。只有a61,然后是b71,依此类推。
如何修改我的连接查询?
答案 0 :(得分:4)
您不能在join
条件下执行此操作,但添加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 }
请注意,您可能希望使用int.TryParse
并验证解析是否成功