title: Specified Cast not Valid error using Nhibernate
body: <p>Using Nhibernate, Visual Studio 2010, C#.</p>
  
  <p>I am having a problem converting a Decimal? type. The code gives a </p>
  
  <blockquote>
    <p>Specified Cast is not valid error</p>
  </blockquote>
  
  <p>and fails on the .UniqueResult&lt;> line. </p>
  
  <p>Following is my code.  </p>
  
  <pre><code>private decimal? GetCostValueFromQuery(string query, ItemPriceContext item)
  {
      var session = ActiveRecordMediator.GetSessionFactoryHolder()
                                        .CreateSession(typeof(object));
      return session.CreateSQLQuery(string.Format(query, item.ItemCode))
                    .UniqueResult&lt;decimal?&gt;();
  }
  </code></pre>
  
  <p>The result of my SQL query is <code>62.3891005516052</code></p>
  
  <p>I suspect the result has a lot of decimal places and hence fails.</p>
  
  <p>Any suggestions how I could Round the result or reduce the result such that it is supported?</p>