일부 매개 변수를 기반으로 문자열 목록이 주어진 두 날짜 사이에 '트랜잭션'을 찾는 방법이 있습니다. 목록이 1000보다 크면 목록에서 반복을 시도하는 스택 오버플로 예외가 발생합니다.LINQ to SQL의 스택 오버플로 예외
은 여기 비주얼 스튜디오가 처리 할 수있는 지점을지나갑니다 ... 여기 내 코드
public List<string> CodesWithTransactionsBetweenDates(DateTime startInclusive, DateTime endExclusive, List<string> associatedCodes, int marketId)
{
List<string> codesWithTransactionsInPeriod = new List<string>();
using (var context = new MarketPlaceEntities())
{
var transactionList = (from transactions in context.Transactions
where
associatedCodes.Contains(transactions.User.Code) &&
transactions.MarketId == marketId &&
transactions.Date >= startInclusive &&
transactions.Date < endExclusive
group transactions by transactions.User.Code into uniqueIds
select new { UserCode = uniqueIds.Key });
foreach (var transaction in transactionList)
{
codesWithTransactionsInPeriod.Add(transaction.UserCode);
}
return codesWithTransactionsInPeriod;
}
}
이다 스택 추적입니다.
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.VisitChildren(System.Data.Query.InternalTrees.Node n) + 0x3 bytes
System.Data.Entity.dll!System.Data.Query.PlanCompiler.GroupAggregateRefComputingVisitor.VisitDefault(System.Data.Query.InternalTrees.Node n) + 0x2b bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.VisitRelOpDefault(System.Data.Query.InternalTrees.RelOp op, System.Data.Query.InternalTrees.Node n) + 0xe bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.VisitApplyOp(System.Data.Query.InternalTrees.ApplyBaseOp op, System.Data.Query.InternalTrees.Node n) + 0xe bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.Visit(System.Data.Query.InternalTrees.OuterApplyOp op, System.Data.Query.InternalTrees.Node n) + 0xe bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.OuterApplyOp.Accept(System.Data.Query.InternalTrees.BasicOpVisitor v, System.Data.Query.InternalTrees.Node n) + 0x10 bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.VisitNode(System.Data.Query.InternalTrees.Node n) + 0x14 bytes
System.Data.Entity.dll!System.Data.Query.InternalTrees.BasicOpVisitor.VisitChildren(System.Data.Query.InternalTrees.Node n) + 0x60 bytes
내 질문에 내가 스택 오버플로 예외에 대해 걱정할 필요가 없도록이 쿼리를 처리 할 수있는 방법이 무엇입니까?
어떤 Linq 버전을 사용하고 있습니까? 이 문제를 일으킬 수있는 버그 4.0 이전 버전이있었습니다 : http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40 * "이제는 Contains가 self- IQueryable을 참조하고 스택 오버플로가 발생하지 않습니다. "* –
@MatthewWatson .NET Framework 4.0을 사용하고 있습니다. 감사합니다. :) –
스택 오버플로를 처리하기위한 일반적인 제안 : 디버거의 호출 스택을보고 어떤 메소드가 포함되어 있는지 확인하십시오. –