Calling an Oracle function using NHibernate

  1. Tested with NHibernate 2.1.2 and Oracle 11g.
  2. Needs Oracle.DataAccess (not System.Data.OracleClient). Tested with Oracle.DataAccess 2.111.6.0 AMD64.
  3. If your Oracle function returns a scalar value of datatype number, the .NET object will be a Decimal.

NHibernate config:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.driver_class">
      NHibernate.Driver.OracleDataClientDriver
    </property>
  </session-factory>
</hibernate-configuration>

C# code:

var result = nhibernateSession
    .CreateSQLQuery("select GetSomeValue(:p_parameter1) from dual")
    .SetParameter("p_parameter1", parameter1)
    .UniqueResult();

// GetSomeValue returns a scalar of datatype number; result will be object of type Decimal

var someValue = Convert.ToInt32(result);

17 January 2012 | Uncategorized | Comments

Comments:

  1.  
  2.  
  3.  
  • Pages
    • About
    • Professional Profile
  • Blogroll

    • Baby Boon
    • bibliobibuli
    • Dark Angel
    • eric forbes's book addict's guide
    • fadzli.com
    • GojiSoft Blog
    • jusupov.com
    • Linux or Windows
    • mang0.net
    • My Manhood Blog
    • My way in life
    • nazham.com
    • Nurba
    • octalforty
    • onenaught.com
    • Prashant Rajan
    • Random thoughts on software
    • Rasyadi's Blog
    • Rojak Campoq Blog
    • romantika.name
    • Sa'eed & 'Aatikah
    • stainedhead
    • Synersov Alive
    • The Melody
    • Tze's Blog
    • Unpredictability and Surprises
    • Writing by Amir
    • [18:18pm]
  • Categories:
    • .NET
    • Agile
    • AJAX
    • Ancient history
    • Applications
    • ASP
    • ASP.NET
    • Book review
    • C#
    • Cars
    • Cartoons
    • Crystal Reports
    • CSS
    • English
    • Entity Framework
    • FCKEditor
    • Fiction
    • HTML
    • HTTP
    • Javascript
    • jQuery
    • LAMP
    • LINQ
    • MS SQL
    • MySQL
    • PHP
    • Politics
    • Project management
    • Silverlight
    • Software engineering
    • Travel
    • uISV
    • Uncategorized
    • VB6
    • Windows
    • WordPress
  • Meta:
    • RSS
    • Comments RSS
    • Valid XHTML
    • XFN
    • WP
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.