I am new to Dapper though I am aware about ORMs and DAL and have implemented DAL with NHibernate earlier.
Example Query: -
string sql = \"SELECT * FR
No, dapper will not adjust your query. The immediate way to tell this is simply: does the method return IEnumerable...
vs IQueryable...
? If it is the first, then it can only use local in-memory mechanisms.
Specifically, by default, Query
will actually return a fully populated List<>
. LINQ's Count()
method recognises that and just accesses the .Count
property of the list. So all the data is fetched from the database.
If you want to ask the database for the count, ask the database for the count.
As for mechanisms to view what is actually sent to the database: we use mini-profiler for this. It works great.
Note: when you are querying exactly one row: QueryFirstOrDefault
(and the other variants you would expect) exist and have optimizations internally (including hints to ADO.NET, although not all providers can act on those things) to do things as efficiently as possible, but it does not adjust your query. In some cases the provider itself (not dapper) can help, but ultimately: if you only want the first row, ask the database for the first row (TOP
or similar).