How to get SqlDataReader with Dapper?

ado.net dapper

Question

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?

Accepted Answer

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 = (SqlDataReader)
    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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why