title: Managing connection with non-buffered queries in Dapper
body: <p>I have recently started using <a href="https://code.google.com/p/dapper-dot-net">Dapper</a>, everything seems nice and easy but there is one thing that keeps confusing me: Connection Management.</p>
  
  <p>As per the <a href="https://code.google.com/p/dapper-dot-net/#Limitations_and_caveats">documentation</a>:</p>
  
  <blockquote>
    <p>Dapper does not manage your connection's lifecycle, it assumes the
    connection it gets is open AND has no existing datareaders enumerating
    (unless MARS is enabled)</p>
  </blockquote>
  
  <p>In light of this I started doing this inside the implementation of my repository methods:</p>
  
  <pre><code>using (var db = new SqliteConnection(connectionString)) {
      // call Dapper methods here
  }
  </code></pre>
  
  <p>Then I came across a table with a large number of records, so I though of returning an <code>IEnumerable&lt;T&gt;</code> by passing <code>buffered: false</code> to the <code>Query&lt;&gt;</code> method, and when I started enumerating the enumerable in the front end, boom an exception saying the connection was closed and disposed which is expected since I am wrapping my calls with the preceding using block.</p>
  
  <p><strong>Question:</strong> Best way to solve this ?<br>
  <strong>Side question:</strong> Is the way I am managing the connection the preferred way to go about it ?</p>