title: EF generates wrong query, causing exception: Must declare the scalar variable '@...'
body: <p>I am using Entity Framework 4.3, and below is my code (BTW, the RealPrice field of the gift table is of decimal type):</p>
  
  <pre><code>var filters = new StringBuilder();
  var parameters = new List&lt;object&gt;();
  
  decimal numRealPrice = 25.00m;
  filters.Append("RealPrice = @RealPrice");
  var paramRealPrice = new SqlParameter("@RealPrice", SqlDbType.Decimal);
  paramRealPrice.Value = numRealPrice;
  parameters.Add(numRealPrice);
  
  string sqlStatement = "SELECT * FROM gift WHERE ";
  
  sqlStatement = sqlStatement + filters;
  
  List&lt;OM_Gift_BO&gt; gifts = this.objEntity.ExecuteStoreQuery&lt;OM_Gift_BO&gt;(sqlStatement, parameters.ToArray()).ToList();
  
  //....
  </code></pre>
  
  <p>And the framework somewhat generated a SQL query(according to Express profiler 2.0):</p>
  
  <pre><code>exec sp_executesql N'SELECT * FROM gift WHERE RealPrice = @RealPrice',N'@p0 decimal(4,2)',@p0=25.00
  go
  </code></pre>
  
  <p>I have no idea where does the name 'p0' come from, however, since it is different from RealPrice, I got an exception saying:</p>
  
  <blockquote>
    <p>Must declare the scalar variable "@RealPrice".</p>
  </blockquote>
  
  <p>Well, this method works OK with string type parameters.</p>
  
  <p>Any help is appreciated, thanks in advance.</p>