开发者

When does an Entity Framework object dispose of its data?

Say that I have the following code:

using (var db = new MyDatabaseContext())
{
    foreach (var entity in db.LargeEntities)
    {
        byte[] data = entity.LargeBlob;
        File.WriteAllBytes("c:\\" + entity.FileName);
    }
}  

When will the data for each entity.LargeBlob be ready for garbage collection? During the loop? After the using statement? I'm done wit开发者_运维问答h the objects after the WriteAllBytes line, so I'd like it to be disposed as soon as possible.


It is ready for gc after the Using block. Because EF keeps a local copy of the loaded items you have to dispose Context to release the cached items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜