【发布时间】:2016-07-28 18:08:40
【问题描述】:
我有两个列表会说 ListA 和 ListB。我需要遍历 ListB 并将 ID 与 ListA 进行比较。如果有匹配项,那么我需要从 ListB 中删除该项目并将其替换为 ListA 中的匹配项目/对象。
我一直在看THIS 文章。我也看过Intersect。但我真的不确定如何让它与 Linq 一起使用。
这是我的代码:
ListB 是在 else where 生成并传入的查询
var itemsForListA = Context.Set<Item>().AsQueryable();
var ListA = from i in itemsForListA
where i.ReplacementItemID != null
&& (i.ItemStatus == "DISC" || i.ItemStatus == "ACT"
&& i.StoreID == null)
select i;
foreach (var i in ListB)
{
ListB = ListA.Where(x => x.Id == ListA.Id);
}
我以为我可以做这样的事情。我是否必须首先在 ListB 中找到 id 并将其删除,然后将新 id 从 ListA 附加到 B?
【问题讨论】:
标签: c# linq ienumerable