What will do with a predicate?

If I have a method that returns List of Dogs, then Dapperconverts the predicate Whereto SQLWhere? or does he first get all the dogs and then filter the list?

public IList<Dog> GetDogsBy(Func<Dog, bool> predicate)
{
    return db.Query<Dog>("SELECT * FROM Dog",null).Where(predicate).ToList();
}
+4
source share
2 answers

It depends on the resolution of the overload when enabled Where.

If the result of the call Queryis List<Dog>, and you have a directive using System.Linq;, and the argument is a delegate, then it Wherewill be resolved to the LINQ-to-objects version Where. Thus, the selection request will be executed on the server, and then Wherewill be executed on the client.

Query IQueryable<Dog>, Expression, Where, . , Where , , .

+17

SQL trnalsation, , . , , IL , .NET API, .

Func<...> Expression<Func<...>>, , , , , , , .

public IList<Dog> GetDogsBy(Expression<Func<Dog, bool>> predicate)

, Dapper.

+3

All Articles