If I have a method that returns a List of Dogs, does Dapper convert the Where predicate into a SQL Where? or does it get all the dogs first and then filter the list?
public IList<Dog> GetDogsBy(Func<Dog, bool> predicate)
{
return db.Query<Dog>("SELECT * FROM Dog",null).Where(predicate).ToList();
}
It depends on what overload resolution does when resolving the Where.
If the result of the call to Query is a List<Dog> and you have a using System.Linq; directive, and the argument is a delegate, then the Where will resolve to the LINQ-to-objects version of Where. So the select query will run on the server, and then the Where will run on the client.
If the result of Query is IQueryable<Dog> and the argument is an Expression then overload resolution will choose the Where which combines with the existing query. When that query is executed, the Where runs on whatever side the query providers chooses to run it on, which is typically the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With