Imagine the following code.
string city = "Paris";
var query = _context.Customers.Where(c => c.City == city);
city = "London";
foreach (var c in query)
With this code, the foreach is on customers from London.
Sometimes it’s the scenario we want but in many other ones, you expected customers from Paris (the value of city when you define the query).
With LINQ To WAQS we get customers from Paris by default and you have an optional parameter on AsAsyncQueryable method to choose the LINQ default one:
private IAsyncQueryable<Customer> FilterCustomersByAddress(AddressFilter f)
IAsyncQueryable<Customer> query = _context.Customers.AsAsyncQueryable(ParameterMode.OnExecution);
if (f != null && f.City != null)
query = query.Where(c => c.City == f.City);