Linq 2 个列表无需选择即可选择
本文关键字:选择 可选择 列表 string Linq | 更新日期: 2023-09-27 18:32:10
我目前有 3 个列表
List<string>machines
List<string>productCodes
List<ProductionData> productionData
我需要根据生产数据列表检查机器和生产代码。有没有办法做到这一点,而不需要做一台Foreach机器,然后做Foreach productCodes。请参阅下面的代码
int productionCount = 0;
var productionData = (from p in Entities.Scrappages
where p.Date >= p.Date && p.Date <= p.Date
select p).ToList();
List<string>machines = new List<string>();
List<string>productCodes = new List<string>();
foreach (var machine in machines)
{
foreach (var productCode in productCodes)
{
productionCount =
(from p in productionData
where p.MachineID.Equals(machine) && .ProductionCode.Equals(productCode)
select p).Count();
}
}
有没有办法在没有前方的情况下做到这一点?
你可以尝试这样的事情:
var productionCount = (from pd in productionData
join pc in productCodes
on pd.ProductionCode equals pc
join m in machines
on pd.MachineId equals m
select pd).Count();