我有一种方法,它基于一些参数在给定字符串列表的两个日期之间找到“交易”。当列表大于 1000 时,我得到一个堆栈溢出异常,试图在列表上进行迭代。
这是我的代码
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
我的问题是有什么方法可以处理这个查询,这样我就不必担心堆栈溢出异常?