【发布时间】:2013-01-14 09:17:18
【问题描述】:
基本上我使用实体框架来查询一个巨大的数据库。我想返回一个字符串列表,然后将其记录到一个文本文件中。
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 时出现异常。
例外是:
引发了“System.OutOfMemoryException”类型的异常。
“System.OutOfMemoryException”类型的第一次机会异常 发生在 System.Data.Entity.dll 中
更新:
我想用一个不同的查询说:选择前 1000 个然后添加到列表中,但我不知道 1000 之后是什么?
【问题讨论】:
-
提示:升级你的内存 :-)
-
您能否提供有关异常的完整信息以及内部异常(如果有)以及堆栈跟踪。
-
temp 的一般长度是多少?
-
内存4GB,够用了……
标签: c# sql-server entity-framework c#-4.0 ef-code-first