【发布时间】:2012-05-02 12:49:25
【问题描述】:
我有这个问题:
var newComponents = from ic in importedComponents
where !existingComponents.Contains(ic)
select ic;
importedComponents 和 existingComponents 的类型为 List<ImportedComponent>,并且仅存在于内存中(与数据上下文无关)。在本例中,importedComponents 有超过 6,100 个项目,existingComponents 有 511 个项目。
这个语句完成的时间太长(我不知道多长时间,我在 20 分钟后停止脚本)。我尝试了以下方法,但执行速度没有提高:
var existingComponentIDs = from ec in existingComponents
select ec.ID;
var newComponents = from ic in importedComponents
where !existingComponentIDs.Contains(ic.ID)
select ic;
任何帮助将不胜感激。
【问题讨论】: