Now Dapper (and for quite some time) has been doing this internally. It just works β’
Original (outdated) answer:
You are not mistaken. The reason I didnβt notice that this inconvenience is because for obsolete reasons (in particular: we used LINQ-to-SQL exclusively), our main connection information is DataContext , so we re-expose the methods dapper as extension methods on a DataContext .
Stupid thing: what do these methods do:
using(db.Connection.EnsureOpen()) { db.Connection.{the dapper method} }
Here, EnsureOpen is a cheeky method that:
- if the connection is open, returns null
- Otherwise, it opens the connection and returns an IDisposable token, which closes the connection when completed
So: we obviously felt exactly your pain, but we realized it even further.
Please register this as a feature request. We have all the code (although I need to tweak it a bit to fit the βreaderβ for unbuffered data) - there is absolutely no reason dapper cannot own it.
Marc Gravell Sep 27 '12 at 20:01 2012-09-27 20:01
source share