title: Exception in OrmLite: Must declare the scalar variable
body: <p>Our code has a SqlExpression, which at its bare minimum is something like:</p>
  
  <pre><code>var q = db.From&lt;Users&gt;();
  
  q.Where(u =&gt; u.Age == 25);
  
  totalRecords = db.Scalar&lt;int&gt;(q.ToCountStatement());
  </code></pre>
  
  <p>q.ToCountStatement() generates the following query:</p>
  
  <pre><code>SELECT COUNT(*) FROM "Users" WHERE ("Age" = @0)
  </code></pre>
  
  <p>However, db.Scalar() throws an exception: Must declare the scalar variable "@0". This has started occurring in recent versions (tested in 4.0.54). The same code was working fine until v4.0.50. I've checked the release notes, but couldn't find a related change.</p>
  
  <p>Even passing a parameter throws the same exception:</p>
  
  <pre><code>totalRecords = db.Scalar&lt;int&gt;(q.ToCountStatement(), 25);
  </code></pre>
  
  <p>Is it a bug, or my oversight?</p>
  
  <p>Secondly, is it possible to get <code>q.ToCountStatement()</code> to generate a more optimized query with <code>COUNT(Age)</code> or <code>COUNT([PrimaryKey])</code> instead of <code>COUNT(*)</code>?</p>