8

Does it load all records in this code or uses something like SqlDataReader?

using (var c = new SqlConnection(_options.TargetConnectionString))
{
    c.Open();
    foreach(var record in c.Query("select * from Users")) // suppose N+1 records
    {
        // all records loaded or read one by one here? 
        // some work here...
    }
}
Artyom
  • 3,507
  • 2
  • 34
  • 67
  • consider using SQL Server Profiler to investigate this. But seems like all records are loaded in your case. – Vladimir May 30 '16 at 12:55

1 Answers1

12

Both options are supported. By default, the data is buffered into a List<T> on the basis that most queries are fairly small, and to avoid the "multiple recordsets" limitation. To obtain the underlying list without an extra allocation, use the provided .AsList() extension method. If, however, you want unbuffered data: pass buffered: false. This will give you an enumerator that wraps the raw IDataReader - suitable for huge queries.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 1
    I see. Another good answer at http://stackoverflow.com/questions/13026558/explanation-of-dapper-buffer-cache – Artyom May 30 '16 at 19:07