title: Getting "The SqlParameter is already contained by another SqlParameterCollection." error while using SqlQuery command
body: <p>I am trying to parameterize a dynamic query and run it using SqlQuery method in Entity Framework code first. </p>
  
  <p>The first time I execute SqlQuery it works as expected so I am sure there is nothing wrong with query or parameters but immediately I execute the same command with the same parameters second time and I get this error </p>
  
  <blockquote>
    <p>"The SqlParameter is already contained by another SqlParameterCollection." </p>
  </blockquote>
  
  <p>Since I am already using <code>ToList()</code> method here, I have no idea what the cause could be!</p>
  
  <p>Here is the simulated code.</p>
  
  <pre><code>using (var context = Common.GetDbContext())
     {
          var parameters = new List&lt;SqlParameter&gt;();
  
           //populating parameters here...
  
           var sqlQuery = "Select * from MyTable where UserId=@p1 and And Active=@p2";
  
           // first time
           var result = context.Database.SqlQuery&lt;ResultType&gt;(sqlQuery, parameters.ToArray()).ToList();
           //second time
           result = context.Database.SqlQuery&lt;ResultType&gt;(sqlQuery, parameters.ToArray()).ToList();
    }
  </code></pre>
  
  <p>Any idea?</p>