Search code examples
c#deferred-execution

Deferred execution linq c# Tolower toupper tostring


Im wondering when I do this:

IQueryable<customer> customers = new IQueryable<customer>();
var customers = db.customers.Where(x=> x.Name.ToLower() == "john");

Does the deferred execution stop at the use of methods like "ToLower() or ToUpper or Tostring"?


Solution

  • Does the deferred execution stop at the use of methods like "ToLower() or ToUpper or Tostring"?

    It does not matter which method is called the line x.Name.ToLower() == "john" will not be executed (actually the complete Where() will not be called) unless the customers variable is materialized or enumerated or unless you bring the results in memory by calling ToList() at the end of the query.