Linq <string> 2列出select而不必foreach </string>

时间:2014-11-26 15:16:34

标签: c# linq

我目前有3个列表

List<string>machines 
List<string>productCodes
List<ProductionData> 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();

    }
}

如果没有foreach,有没有办法做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

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();
相关问题