DBAs have told me that when using T-SQL:
select count(id) from tableName
is faster than
select count(*) from tablenName
if id is the primary key.
Extrapolating that to LINQ-TO-SQL is the following accurate?
This LINQ-to-SQL statement:
int count = dataContext.TableName.Select(primaryKeyId => primaryKeyId).Count();
is more performant than this one:
int count = dataContext.TableName.Count();
As I understand it there’s no difference between your two
select countstatements.Using LINQPad we can examine the T-SQL generated by different LINQ statements.
For Linq to SQL both
and
generate the same SQL
For Linq to Entites, again they both generate the same SQL, but now it’s