問題描述
LINQPad / LINQ To SQL ‑ 簡單查詢僅在循環內執行時才會引發內存不足 (LINQPad / LINQ To SQL ‑ Simple Query Throws Out of Memory Only When Executed Inside a Loop)
我有一個具有以下關係的數據庫:
計算 ‑
我需要循環所有的計算,然後查詢相關的 BinaryData 行。BinaryData 的查詢是 BinaryData.bdCalculationKey 上的一個簡單 where 子句。運行此查詢在獨立運行時會立即返回,但在計算循環內運行時會拋出內存不足異常。代碼如下所示:
var groupName = "NYPH";
var serverName = "192.168.100.132";
var tahitiDB =
new BTR.Evolution.Data.DataContexts.Legacy.Profile.BtrProfile(
BTR.Evolution.Core.Registry.ProfileDatabase( groupName, serverName )
) { ObjectTrackingEnabled = false, DeferredLoadingEnabled = false, CommandTimeout = 30 };
var data = tahitiDB.Calculations.Where(c => c.Profile.Client.cName == groupName && !c.calcIsFailed);
data.Count().Dump();
tahitiDB.BinaryDatas
.Where(b => b.bdCalculationKey == new Guid( "3d53aa12‑0353‑e911‑83b4‑005056b9729f" ) )
.Dump();
foreach( var p in data )
{
p.calcKey.Dump();
tahitiDB.BinaryDatas
.Where(b => b.bdCalculationKey == p.calcKey )
.Select(b => new { b.bdKey, b.bdCalculationKey, b.bdFilename, b.bdDateCreated })
.Dump();
break;
}
這是 LINQPad 結果的屏幕截圖(也顯示了成功轉儲查詢outside循環):