The Best C# Programmer In The World - Ben Perkins Member Login  | Newsletter | RSS Feeds


 
 
 
TheBestCSharpProgrammerInTheWorld.com 
 
The Best C# Programmer In The World - Ben Perkins
Using ODP.Net with NHibernate and System.Decimal  
 
Using ODP.Net with NHibernate and System.Decimal
 
Please rate:
 
A few months ago I wrote a question asking for solutions to this error.
 
There were some good answers but none of them provided me with a work around that was database independent. At least something that would work with both Oracle and SQL Server.
 
I was implementing some calculated fields in NHibernate and I again had to retrieve and modify a decimal from the database. Again I received the error ‘The arithmetic operation has caused an overflow.’
 
What I found was that the database method ROUND() is the same on Oracle and SQL Server. So I simply had to wrap my decimal in a ROUND() method.
 
For example, in my calculated field I needed to multiply Time by Cost. Cost is a decimal.
 
By rounding the TotalCost to 2 decimal places, I am able to use this in both Oracle and SQL Server.
 
 
                         <property name="TotalCost" 
                                   formula="ROUND(((Time/60)*Cost), 2)"  
                                   type="decimal"  />                       
                         
 
You need to note that this error happens if you use ODP.Net to connect to Oracle.
 
 
Feedback / Question
 
Your Name:Your Email:
 
Subject:
 
Feedback/Question:
 
 
 
I had to remove the capability to leave feedback due to this. Will be back soon.
 
 
page.Translate()
 
 
blog.Stats()
 
  Posts: 103
  Comments: 86
  Fundamentals: 13
 
my.Book()

 
me.About()
 
 
 
 
 
blog.Archive()
 
2012 February  (4)
2012 January  (5)
2011 December (2)
2011 November (6)
2011 October (7)
2011 September (7)
2011 August (9)
2011 July (9)
2011 June (8)
2011 May (9)
2011 April (7)
2011 March (9)
2011 February (8)
2011 January (8)
2010 December (7)
2010 November (8)
2010 October (4)
 
site.Visits()
 
free counters
 
tag.Cloud()
 
code.Disclaimer()
 
The sample code on this website is provided to illustrate a concept and should not be used in applications or Web sites without proper professional consultation, as it may not illustrate the safest coding practices. I assume no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
 
   


The Best C# Programmer In The World - Ben Perkins, © 2010, All Rights ReservedContact Ben