从巨大的IEnumerable填充数据表需要很长时间 [英] fill a data table from a huge IEnumerable takes a long time
问题描述
您好
我使用数据表将其作为存储过程的参数传递。为了填写数据表,我读了一个保存在IEnumerable 中的巨大列表。 (项目,包含数百万条记录)如下所示:
I use a data table to pass it as a parameter of a stored procedure. To fill the data table, I read a huge list saved in IEnumerable (items, Contains millions of record) as below:
foreach (Model userJobPostMatch in items) {
dataTable.Rows.Add();
}
然后将dataTable传递给存储过程。但是向dataTable添加行需要很长时间。这样做的优化方法是什么?是否可以使用多线程 ?
Then pass the dataTable to the stored procedure. But it takes a long time to add rows to dataTable. What is the optimized way to do that? is it possible to use multi-threading ?
推荐答案
嗨波斯语dev eloper,
>>然后将dataTable传递给存储过程。但是向dataTable添加行需要很长时间。这样做的优化方法是什么?是否可以使用多线程 ?
>>Then pass the dataTable to the stored procedure. But it takes a long time to add rows to dataTable. What is the optimized way to do that? is it possible to use multi-threading ?
我不建议您从数据库加载大量数据,您可以考虑处理分页,在您的情况下。 关于带分页的ado.net存储过程,请参考:
I don't suggest that you load a huge data from database, you could consider to handle paging and in your case. about ado.net stored procedure with paging, please refer to:
https://www.codeproject.com/Articles/590341/Stored-Procedure-with-Sorting-Paging-and-Filtering
此外,您可以将数据加载到datatable而不是IEnumerable,请参阅以下链接。
In addition, you could load data into datatable instead of IEnumerable, please refer to the following link.
https://stackoverflow.com/questions/13402003/how-to-populate-a -datatable-from-a-stored-procedure
我认为我们不能使用多线程,因为使用多线程,我们无法知道哪些记录有已被添加到数据表中。
I don't think we could use multi-threading, because with multi-threading, we could not know what records have been added into the datatable.
祝你好运,
张龙
这篇关于从巨大的IEnumerable填充数据表需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!