Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper Query(..): stream or loads all?

Tags:

c#

orm

dapper

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...
    }
}
like image 949
Artyom Avatar asked May 30 '16 12:05

Artyom


People also ask

What is dapper query?

Dapper is an example of Micro ORM, in fact, it is called the King of Micro ORM because of its speed and ease of work. Dapper works in the following way – First, it creates an IDbConnection object and allows us to write queries to perform CRUD operations on the database.

Does dapper cache?

Dapper caches information about every query it runs, this allow it to materialize objects quickly and process parameters quickly. The current implementation caches this information in a ConcurrentDictionary object.

Does dapper use SqlClient?

SqlClient and SqlConnection , but Dapper supports other databases that use the DbConnection abstraction. We also need a projection class representing the results of our SQL query.

Is Dapper case sensitive?

Dapper's(SqlMapper) Query method over the Connection factory runs the SQL query, then maps the database result to Employee class and returns as a list of employees. Note : Only matching class and table properties are mapped to list of employee, they are case sensitive.


1 Answers

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.

like image 113
Marc Gravell Avatar answered Sep 22 '22 02:09

Marc Gravell