title: SqlParameter is already contained by another SqlParameterCollection, but I don't see how
body: <p>I have the following code.</p>
  
  <pre><code>// Get total row count and build Pagination object
  var countQuery = ArticleServerContext.Database.SqlQuery&lt;int&gt;("GetFullTextSearchCount @SearchTerm",
      new SqlParameter("@SearchTerm", fullTextQuery));
  Pagination pagination = new Pagination(countQuery.Single(), page ?? 1);
  // Get search results for current page
  var resultsQuery = ArticleServerContext.Database.SqlQuery&lt;ArticleSummary&gt;("GetFullTextSearchResults @SearchTerm, @SkipRows, @TakeRows",
      new SqlParameter("@SearchTerm", fullTextQuery),
      new SqlParameter("@SkipRows", pagination.SkippedRows),
      new SqlParameter("@TakeRows", pagination.RowsPerPage));
  // Build model
  SearchResultsModel model = new SearchResultsModel
  {
      SearchTerm = searchTerm.Trim(),
      Pagination = pagination,
      Results = resultsQuery.ToList()   // &lt;=== Here's where the error happens
  };
  </code></pre>
  
  <p>When I attempt to enumerate <code>resultsQuery</code>, I get the following error message.</p>
  
  <blockquote>
    <p>The SqlParameter is already contained by another SqlParameterCollection.</p>
  </blockquote>
  
  <p>This error message seems clear enough, but I cannot see where I'm adding an <code>SqlParameter</code> to more than one <em>anything</em>. The only thing I can imagine is that the first parameter to both calls are identical. Could C# be combining them somehow? Either way, I need them to contain the same data.</p>
  
  <p>Can anyone see what's happening here?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Sorry, this turned out to be a debugging issue. I had another issue that prevented the results I expected. But when I break in the debugger and step through my code, I get the error mentioned above.</p>
  
  <p>It seems that the code executes using the <code>SqlParameter</code> in question, and then I attempt to inspect the contents of the query and the query runs again with the same <code>SqlParameter</code>, and <em>that</em> is what is causing the error.</p>
  
  <p>Unfortunately, now that I have a bounty, I cannot delete the question.</p>