title: Stack Overflow Exception in LINQ to SQL
body: <p>I have a method that based on some parameters finds 'Transactions' between two dates given a list of strings. When the list is > 1000, I get a stack overflow exception trying to iterate on the list.</p>
  
  <p>Here is my code</p>
  
  <pre><code>public List&lt;string&gt; CodesWithTransactionsBetweenDates(DateTime startInclusive, DateTime endExclusive, List&lt;string&gt; associatedCodes, int marketId)
      {
          List&lt;string&gt; codesWithTransactionsInPeriod = new List&lt;string&gt;();
          using (var context = new MarketPlaceEntities())
          {
              var transactionList = (from transactions in context.Transactions
                                     where
                                      associatedCodes.Contains(transactions.User.Code) &amp;&amp;
                                      transactions.MarketId == marketId &amp;&amp;
                                      transactions.Date &gt;= startInclusive &amp;&amp;
                                      transactions.Date &lt; 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;
          }
      }
  </code></pre>
  
  <p>Here is the stack trace... it goes past the point which visual studio can handle.</p>
  
  <pre><code>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    
  </code></pre>
  
  <p>My question is what is a way I can handle this query so that I do not have to worry about a stack overflow exception?</p>