Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get SqlDataReader with Dapper?

Tags:

ado.net

dapper

I have a web application that uses old school SqlHelper class.

I want to create my custom SqlHelper which uses Dapper underneath. So, how can I get SqlDataReader from Dapper?

like image 546
Imran Qadir Baksh - Baloch Avatar asked Sep 21 '14 07:09

Imran Qadir Baksh - Baloch


1 Answers

There is an ExecuteReader method that hands you back the data-reader that the connection generated: you can cast this if you know it is actually a SqlDataReader. In this scenario, dapper only processes parameters and literal injection.

using(var reader = (DbDataReader)
    conn.ExecuteReader(sql, args))
{
    // use reader here
}

I am, however, more than a little intrigued as to what you want SqlHelper to do that dapper doesn't already do (but better). Genuine question: I like improving the library. If there is a gap, let me know.

like image 100
Marc Gravell Avatar answered Oct 23 '22 10:10

Marc Gravell