title: How to compare a string column to a number (as a decimal) in Linq
body: <p>I have a database with an amount field - it's a decimal, although the database schema has the column defined as a string. I want to be able to run a Linq query to find values based on a number for the amount.</p>
  
  <p>There are questions like <a href="https://stackoverflow.com/questions/578231/issues-doing-a-string-comparison-in-linq">this</a> and <a href="https://stackoverflow.com/questions/3365122/how-to-compare-a-string-column-value-in-a-linq-query">this</a> that talk about using the CompareTo method, but that doesn't work in this situation.  For example, I have the following bill amounts in the database:</p>
  
  <pre><code>556
  130
  1450
  410
  </code></pre>
  
  <p>the following code:</p>
  
  <pre><code>from t in test
  where t.BillAmount.CompareTo("50") &gt; 0
  select t
  </code></pre>
  
  <p>will return value <code>556</code> but not any of the other values, even though they are all above the decimal value of 50.</p>
  
  <p>Changing the where line to:</p>
  
  <pre><code>    where t.BillAmount.CompareTo("50") &lt; 0
  </code></pre>
  
  <p>will return <code>130</code>, <code>1450</code>, and <code>1450</code> as those are "less" then 50 as a string, but not as a number.</p>
  
  <p>I'm not using the entity framework, so I can't do something like:</p>
  
  <pre><code>where SqlFunctions.StringConvert((double)t.BillAmount).Trim() &gt; 50
  </code></pre>
  
  <p>I also don't have any control over the database schema, so I can't change these values. How can I compare the BillAmount field to a number and return the values above/below it?</p>