If I have the following code, is the compiler instantiating each result or is it wise enough to just count how many corresponding records are in the table? If not, it may force me to use a different strategy on larger queries.
from c in context.RendezVous
where c.RepID == repID &&
c.DateHeureRV != null &&
c.DateHeureRV.Value.Date == date.Date
select c).Count();
Thank you!
It depends on the type of
context.If this is an Entity Framework or Linq to SQL query, and
contextisIQueryable<T>, then the query gets turned into a SQL query on the server which just returns the count as a single integer.If this is an in-memory collection (ie:
IEnumerable<T>), each item is iterated in sequence (Linq to Objects) and counted.I suspect the former is true, since you mentioned “table” and you’re not using the LINQ to Dataset extension methods. In that case, you will stay very efficient.