gpt4 book ai didi

c# - Linq 从另一个区间列表中选择任何区间内的所有数字

转载 作者:行者123 更新时间:2023-11-30 15:57:40 24 4
gpt4 key购买 nike

我正在尝试编写 linq lambda select 以从数据库中获取所有记录,这些记录的编号位于其他列表或数据库表的任何特定间隔内。可以说我有一张 table “SOURCE”
+------+------+-------+------+------+
| Col1 | Col2 | reqNr | col5 | col6 |
+------+------+-------+------+------+
| x | x | 9 | x | x |
| x | x | 14 | x | x |
| x | x | 19 | x | x |
| x | x | 24 | x | x |
+------+------+-------+------+------+
我已经选择了表格“INTERVALS”
+------+----+
| from | to |
+------+----+
| 1 | 3 |
| 5 | 10 |
| 15 | 30 |
+------+----+
到 c# 中的对象列表“intervalList”。如何在 linq sql 语句中编写“.Where()”部分以从“SOURCE”获取所有记录,这些记录具有“ReqNr”列值,该列值落在“intervalList”列表的任何间隔中。例如:.where(w => intervalList.any(w.ReqNr > intervalList.from && w.ReqNr < intervalList.to))

最佳答案

你可以这样做:

var result = iRec
.Where(r => intervalList.Any(i => i.From <= r.reqNr && i.To >= r.reqNr))
.ToList();

可以查一下here .

关于c# - Linq 从另一个区间列表中选择任何区间内的所有数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44673095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com