title: performance difference sql query with LINQ and classic asp
body: <p>I'm developing an asp.net web forms 4.5 website,
  and I've come to a problem where I have to perform an sql query
  from sql server originally written by classic asp.</p>
  
  <p>The original query goes like this..</p>
  
  <pre><code>select trait1, trait2, sum(qty) as qty from table2
  right outer join table1 on (table1.col == table2.col)
  where table2.idx is null 
  group by trait1, trait2
  order by trait1, trait2
  </code></pre>
  
  <p>and as I'm writing a .net program, I'm trying to rewrite this query...
  as something like this</p>
  
  <pre><code>var myHashSet = new HashSet&lt;string&gt;(table2.Select(c =&gt; c.col));
  
  from item in table2
  where !myHashSet.Contains(item.col)
  group item.qty by new {item.trait1, item.trait2} into total
  select new
  {
      trait1 = total.Key.trait1,
      trait2 = total.Key.trait2,
      qty = total.Sum()
  } into anon
  order by anon.qty descending
  select anon
  </code></pre>
  
  <p>ps : ignore the order by part.. it's not important</p>
  
  <p>for classic asp, it takes like 1.5 seconds, but for c# asp.net,
  it takes roughly 8 seconds.</p>
  
  <p>The queries are not exactly like that but its almost similar to what I wrote.</p>
  
  <p>I cannot figure out why it's taking so long..
  Can someone tell me why it's taking so long and how I should fix it?</p>