我有两个列表,一个是列表,Equipment
另一个是WorkflowItems
带有Equipment
属性的列表。列表中的Equipment
属性List<WorkflowItem>
只有一个水合值,ProcessId
. 有List<Equipment>
两个特性水合,ProcessId
和Name
。我想List<WorkflowItem>.Equipment.Name
用单Equipment
条记录中的值来水合List<Equipment>
下面的这个 LINQ 查询将选择一个通用项目,基本上做我正在寻找的,但我宁愿只填写原始列表。
var list = from item in workflowItems
join equipment in barcodeEquipmentList on
item.Equipment.ProcessId equals equipment.ProcessId
select new
{
ProcessId = item.Equipment.ProcessId,
EquipmentName = equipment.Name
};
编辑 列表将相对较小,即使做这样的事情也可以(除了这不起作用的事实)
workflowItems.ForEach(x => x.Equipment = from e in barcodeEquipmentList
where e.Process.Id == x.Equipment.Process.Id
select e
);
...最终编辑
但这确实有效:
workflowItems.ForEach(x => x.Equipment = barcodeEquipmentList
.Where(e => e.Process.Id == x.Equipment.Process.Id)
.FirstOrDefault());