Reputation: 228
Is this:
Dim mydata = (From c In dc.Table Select New With {c.ID}).Count
any faster than this:
Dim mydata = (From c In dc.Table Select c).Count
assuming the table has a good number of fields?
Upvotes: 1
Views: 171
Reputation: 3150
The short answer: no.
The SQL generated by the LINQ-to-SQL engine should be essentially the same for both forms (if not exactly the same) because you're calling .Count()
immediately on the query.
A compiled query version, on the other hand, would be faster after the first execution. Here's one way to do a compiled query for this:
Public Shared FetchCount As Func(Of DataContext, Integer) = _
CompiledQuery.Compile(Function(context as DataContext) _
(From c in context.Table Select c).Count())
DataContext
would need to be the Type of the LINQ-to-SQL DBML, and Table
would need to be the appropriate table. And, I believe you'll need to import System.Data.Linq
to have access to CompiledQuery
.
Upvotes: 3