多长时间调用一次DataContext.SubmitChanges()进行大量插入? [英] How often to call DataContext.SubmitChanges() for a large number of inserts?
问题描述
在呼叫SubmitChanges
之前我应该呼叫多少InsertOnSubmit
?我正在从Web服务中添加数据,该数据一次可以返回成千上万条记录. Web服务周围的包装器类将记录公开为IEnumberable
集合,以隐藏复杂的分块机制.
How many InsertOnSubmit
should I call before calling SubmitChanges
? I'm adding data from a web service that can return tens of thousands of records one record at a time. The wrapper class around the web service exposes the records a an IEnumberable
collection to hide an elaborate chunking mechanism.
在提交之前,我应该积累多少插入物的指导原则吗?
Are there guidelines on how many inserts I should accumulate before submitting them?
推荐答案
它还取决于您需要插入的数据类型.有时,我需要插入很多记录(也需要ID的记录)才能在另一个表中插入更多记录.
It also depends on the kind of data you need to insert. Sometimes I need to insert a lot of records, where I also need the ID of, to insert more records in another table.
由于在向数据库提交更改时会分配ID,因此我需要在特定时间调用SubmitChanges.
Because the ID gets assigned when you submit changes to the database, I need to call SubmitChanges on specific times.
如果不需要,我只需一次提交1000左右(取决于我需要插入的记录总数).
When this is not needed, I just submit them with a 1000 at once or so (depending on the total number of records I need to insert).
也许您可以进行一些最适合您的速度测试.取决于硬件,对记录量的期望等.
Maybe you could do some speed tests, which are best for you. Depending on the hardware, expectations of amount of records, etc.
这篇关于多长时间调用一次DataContext.SubmitChanges()进行大量插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!