title: Primary Key count Count in LINQ very slow
body: <p>I thought LINQ to SQL was tuned for performance?</p>
  
  <p>The following LINQ to SQL for counting is very poor</p>
  
  <pre><code>Dim uniqueFactors As Integer = db.LargeTable.Distinct.Count
  </code></pre>
  
  <p>produces:</p>
  
  <pre><code>SELECT COUNT(*) AS [value]
  FROM [dbo].[LargeTable] AS [t0]
  WHERE ([t0].[ID] % @p0) = @p1
  </code></pre>
  
  <p>How every the fastest way to count the number of records based on a primary key is</p>
  
  <pre><code>SELECT  @totalRowCount = rows
  FROM    sysindexes
  WHERE   id = OBJECT_ID('LargeTable')
      AND indid &lt; 2
  </code></pre>
  
  <p>So the question, how can I ensure that LINQ to SQL performs a count quickly when asking for Count(*)?</p>