title: DynamicParameters fails to add template if ForEach is chained after ToList
body: <p>I have a function that dynamically builds sql statements based on an existing model and then adds some common fields that exist in every table.</p>
  
  <p>The problem is that I'm experiencing some odd behaviour when I try to add the common fields.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Data.SqlClient;
  using Dapper;
  
  public class Program
  {
      private static readonly dynamic[] Data = new dynamic[] { new {Foo = 1, Bar = 2}, new {Foo = 3, Bar = 4} }; 
      public static void Main()
      {
          Console.WriteLine("Hello World");
      }
  
      public static void Broken()
      {
          var parameters = ((IEnumerable&lt;dynamic&gt;)Data).Select(x =&gt; new DynamicParameters(x));
          parameters.ToList().ForEach(x =&gt; x.AddDynamicParams(new {Bax = 7}));
          using (var connection = new SqlConnection(""))
          {
              // This fails with a "Must declare scalar variable @Bax".
              connection.Execute("INSERT INTO DataTable(Foo, Bar, Bax) VALUES(@Foo, @Bar, @Bax)", parameters);
          }
      }
  
      public static void Working()
      {
          var parameters = ((IEnumerable&lt;dynamic&gt;)Data).Select(x =&gt; new DynamicParameters(x)).ToList();
          parameters.ForEach(x =&gt; x.AddDynamicParams(new {Bax = 7}));
          using (var connection = new SqlConnection(""))
          {
              // This works fine.
              connection.Execute("INSERT INTO DataTable(Foo, Bar, Bax) VALUES(@Foo, @Bar, @Bax)", parameters);
          }
      }
  }
  </code></pre>
  
  <p>If you'll notice, the only difference is the position of my call to <code>.ToList()</code>. In the <code>Broken</code> function, I call it as part of a chain before <code>.ForEach</code> and in the the <code>Working</code> function, I call it on the same line as the assignment.</p>
  
  <p>I've tried replacing the call to <code>AddDynamicParams</code> with individual <code>Add</code> calls for each parameter, but it doesn't seem to matter. I've also tried doing <code>for(var parameter in parameters) { parameter.AddDynamicParams(new {Bax = 7}) }</code> with no luck.</p>
  
  <p>Unfortunately, there's no good way that aware of to show the <code>templates</code> without setting a breakpoint and examining the <code>.templates</code> attribute of the object in Visual Studio. If someone can provide a better way to demonstrate the template disappearing, I'm all ears.</p>