c# - Linq to Entities figure out count of rows without returning rows -
i hope 1 of guys can me question: given method below, can cause count done on db server rather retrieve rows, , function should not running query each search name, should run 1 sql statement each call of function.
you can simplify query dramatically using contains translated where in clause. count matching rows.
public static int countemployeesbyname(ienumerable<string> namestosearch) { using (var context = new applicationentities()) { return context.employees .where(e => namestosearch.contains(e.name)) .count(); } }
Comments
Post a Comment