title: Writing a class that models a stored procedure for consumption by Dapper
body: <p>I've followed the example on <a href="http://blog.vijay.name/2012/07/dapper-micro-orm-for-oracle-and-microsoft-net/" rel="nofollow">http://blog.vijay.name/2012/07/dapper-micro-orm-for-oracle-and-microsoft-net/</a> to implement Dapper with some of my existing Oracle stored procedures. However, I am a little bit unhappy with the example, because of this block:</p>
  
  <pre><code>using ( var multi = cnn.QueryMultiple( "PKG_USERS.GetUserDetailsForID", param: p, commandType: CommandType.StoredProcedure ) )
  {
      u = multi.Read&lt;User&gt;( ).Single( );
      u.Roles = multi.Read&lt;UserRole&gt;.ToList( );
  }
  </code></pre>
  
  <p>Sure, this logic is easy enough to follow, but what if I have 1000 of these to implement?</p>
  
  <p>I would like to be able to define a class (model) <em>per stored procedure</em>, then execute it using some context (which includes an <code>IDbConnection</code>) according to the following convention:</p>
  
  <ul>
  <li>Each property of the model is a parameter of the stored proceudre</li>
  <li>Each output parameter of the stored procedure is mapped to the appropriate parameter of the model by the rule name = name.</li>
  </ul>
  
  <p>So my model would look something like this:</p>
  
  <pre><code>public class ConcreteSPModel : AbsSPModel
  {
      public string ParamOne { get; set; }
      public string ParamTwo { get; set; }
      //Attributes or other markup to indicate that this is an output parameter
      public List&lt;OtherModel&gt; ParamThree { get; set; }
  }
  </code></pre>
  
  <p>and I would fill it up by:</p>
  
  <pre><code>var params = new OracleDynamicParameters(myConcrete);
  using (var m = Connection.QueryMultiple(myConcrete.CommandText(), param: params, commandType: myConcrete.CommandType())
  {
      myConcrete.FillWith(m);
  
      // OR...
  
      this.FillModel(myConcrete, m);
  }
  </code></pre>
  
  <p>I've implemented something like this before without Dapper, using reflection, but before I go down that path I would like to know if there is anything built into Dapper that could enable me to avoid writing my own code to iterate over the public properties and assign each one by invoking the <code>Read</code> method for its generic argument and generic type?</p>