问题描述
我有一大堆地址列表(ip addr)>百万
I have a large list of addresses(ip addr) > millions
通过EntityFramework有效地移除500k地址
Remove 500k addresses efficiently through EntityFramework
现在,我分成10000个地址的列表,并使用RemoveRange(ListOfaddresses)
Right now, I'm splitting into lists of 10000 addresses and using RemoveRange(ListOfaddresses)
if (addresses.Count() > 10000)
{
var addressChunkList = extension.BreakIntoChunks<Address>(addresses.ToList(), 10000);
foreach (var chunk in addressChunkList)
{
db.Address.RemoveRange(chunk);
}
}
但我得到一个 OutOfMemoryException
这意味着即使我将地址分割成单独的列表,它并不释放资源。
but I'm getting an OutOfMemoryException
which must mean that it's not freeing resources even though I'm splitting my addresses into separate lists.
我可以做什么得到OutOfMemoryException,并在合理的时间内仍然删除大量的地址?
What can I do to not get the OutOfMemoryException and still remove large quantities of addresses within reasonable time?
推荐答案
当我需要做类似的操作时,我已经转过到以下插件(我没有关联)。
When I have needed to do something similar I have turned to the following plugin (I am not associated).
这允许您使用实体框架进行批量删除,而无需选择并加载实体首先进入内存当然更有效率。
This allows you to do bulk deletes using Entity Framework without having to select and load the entity into the memory first which of course is more efficient.
网站示例:
context.Users.Delete(u => u.FirstName == "firstname");
这篇关于删除行时的OutOfMemory> 500000实体框架6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!