有这个模型:
public class VMDeliveryList //[View-model]
{
public List<ContractDelivery> ContractDeliveryList { get; set; }
}
public class ContractDelivery
{
public Contract Contract { get; set; }
public List<Delivery> DeliveryList { get; set; }
}
public class Delivery
{
public int Id { get; set; }
public Employee Employee { get; set; }
}
public class Employee
{
public int Id { get; set; }
}
我需要为不同的 Employee.Id 创建 foreach 循环 感谢您的建议。
请您参考如下方法:
您可以使用 SelectMany展平列表,然后使用 Select
Id
foreach(int id in viewModel.ContractDeliveryList.SelectMany(a => a.DeliveryList)
.Select(b => b.Employee.Id)
.Distinct() )
{
....
}
