我基本上使用Entity Framework来查询一个巨大的数据库。我想返回一个字符串列表,然后将其记录到文本文件中。
List<string> logFilePathFileName = new List<string>();
var query = from c in DBContext.MyTable where condition = something select c;
foreach (var result in query)
{
filePath = result.FilePath;
fileName = result.FileName;
string temp = filePath + "." + fileName;
logFilePathFileName.Add(temp);
if(logFilePathFileName.Count %1000 ==0)
Console.WriteLine(temp+"."+logFilePathFileName.Count);
}
然而,当
logFilePathFileName.Count=397000
时,我遇到了一个异常。异常信息如下:
更新: 我想使用不同的查询,例如:选择前1000个,然后添加到列表中,但是我不知道超过1000之后该怎么办?类型为'System.OutOfMemoryException'的异常被抛出。
'System.Data.Entity.dll'中发生了类型为'System.OutOfMemoryException'的一次性异常。