WAQS: ParameterMode

7 reasons to use WAQS

WAQS documentation

 

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);
    return query;
}
This entry was posted in 12253, 16868. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>