【发布时间】:2020-03-05 11:17:12
【问题描述】:
我有 2 个数据表。大约有 17000 (table1) 和 100000 (table2) 记录。
需要检查“FooName”字段是否包含“ItemName”。还需要获取 "FooId",然后将 "ItemId" 和 "FooId" 添加到 ConcurrentDictionary。
我有这个代码。
DataTable table1;
DataTable table2;
var table1Select = table1.Select();
ConcurrentDictionary<double, double> compareDictionary = new ConcurrentDictionary<double, double>();
foreach (var item in table1)
{
var fooItem = from foo in table2.AsEnumerable()
where foo.Field<string>("FooName").Contains(item.Field<string>("ItemName"))
select foo.Field<double>("FooId");
if(fooItem != null && fooItem.FirstOrDefault() != 0)
{
compareDictionary.TryAdd(item.Field<double>("ItemId"), fooItem.FirstOrDefault());
}
}
它运行缓慢(执行任务大约需要 10 分钟)。
我想让它更快。我该如何优化它?
【问题讨论】:
-
ItemName是一个词还是一个词组? -
@mtkachenko 这是短语。
标签: c# algorithm linq datatable concurrentdictionary