title: How to force Dapper dot net to use its implementation of IDbCommand.ExecuteReader
body: <p>Background:</p>
  
  <p>I'm in the process of integrating Dapper into an existing application that has a legacy DAL based off of the DAAB of years gone by. This is a fairly large code base so it has to be done incrementally. My first attempt is taking a method that calls a reader and populates a collection of objects. </p>
  
  <p>What I'm noticing is that the query extension method seems to be calling the IDbCommand.ExecuteReader and the legacy DAL implementation is being invoked instead of the Dapper version. </p>
  
  <p>So my question is this "Is there a way to explicitly force Dapper to use it's implementation of IDbCommand.ExecuteReader and not the legacy version?"</p>
  
  <p>Setup Connection: The open connection is coming from the existing framework and it completely wraps the IDbConnection interface plus some. There is a lot of security around getting this connection, and other additions that seem to muddy the waters. </p>
  
  <pre><code>private static XyDbConnection GetConnection()
  {
      return XyDbConnection.GetConnection(ExternalFieldDataConstants.ConnectionName.SecureRepositoryConnection);
  }
  </code></pre>
  
  <p>Callsite: Nothing terrible going on here just setup of Dapper in a typical scenario</p>
  
  <pre><code>private void GetFieldMappingTableDapper()
  {
      const string commandText = @"
          SELECT
              OD.ObjectDefId,
              OD.Name,
              FM.LOBField,
              FM.XPath, 
              FM.XPathDataType,
              FM.legacyOnly,
              BA.NAME BusinessAreaName
          FROM    [FieldMapping] FM
          JOIN    [ObjectDef] OD 
          ON  OD.ObjectDefId = FM.ObjectDefId
          JOIN    [BusinessArea] BA 
          ON  BA.BusinessAreaId = OD.BusinessAreaId";
  
      using (var conn = GetConnection())
      {
          _mappingsCache = conn.Query&lt;FieldMappingEx&gt;(commandText).ToList();
      }
  }
  </code></pre>
  
  <p>Pictures are worth a thousand words.</p>
  
  <p>Setting up the call to Dapper:
  <a href="https://i.stack.imgur.com/HCENf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HCENf.png" alt="enter image description here"></a></p>
  
  <p>Now when I step (F11) into the call I get:
  <a href="https://i.stack.imgur.com/sRM5l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sRM5l.png" alt="enter image description here"></a></p>
  
  <p>And now the most interesting part is the invocation of the legacy command object from Dapper. (it seems)
  <a href="https://i.stack.imgur.com/PLnBe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PLnBe.png" alt="enter image description here"></a></p>
  
  <p>I've used Dapper for years, even with Oracle :) and this is the first time I've ever had a hickup, period. </p>
  
  <p>Thank you,
  Stephen</p>