删除行时的OutOfMemory> 500000实体框架6 [英] OutOfMemory when removing rows > 500000 EntityFramework 6

查看:151
本文介绍了删除行时的OutOfMemory> 500000实体框架6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆地址列表(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).

https://github.com/loresoft/EntityFramework.Extended

这允许您使用实体框架进行批量删除,而无需选择并加载实体首先进入内存当然更有效率。

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&gt; 500000实体框架6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆