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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
DataContextwould need to be the Type of the LINQ-to-SQL DBML, andTablewould need to be the appropriate table. And, I believe you’ll need to importSystem.Data.Linqto have access toCompiledQuery.