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