If you have a method that returns an IEnumerable but inside returns an IQueryable will returning an IEnumerable force an execution even though IQueryable defers the execution?
public IEnumerable<Customer> Customers()
{
IEnumerable<Customer> customers = null;
try
{
customers = from c in GetCustomers // IQueryable
where c.Name=="JO"
select c;
}
catch (SqlException ex)
{
}
return customers;
}
The result you return will be an enumerable and will defer execution until you start enumerating it. However, unlike an IQueryable, it won’t be changed by any further operations on it.
For example, if you did something like
.Sum()afterwards, it will be executed on the local machine, whereas an IQueryable may send theSum()to a remote database or web service.