In this post, let us see how to access data from Oracle database using NHibernate, in six simple steps. I am following this NHibernate tutorial from NHibernate FAQ blog as a reference
Step 1: Install NHibernate 2.0.
Step 2: Add a reference to NHibernate dll
Step 3: Create a file hibernate.cfg.xml with the following content. Set the Copy to Output property as “Copy always”
Step 4: Create a mapping file for the table to be accessed
Employee.hbm.xml with the followinf contents and set the Build action property to Embedded Resource and schema property to the nhibernate-mapping.xsd.
If the schema is not available, add the nhibernate-mapping.xsd from the NHibernate application folder.
Include the Primary key under ID tag and rest of the columns under Property tag.
Step 5: Create a public class called Employee with public Virtual propeties EmpId and EmpName.
Step 6: Add NHibernate, NHibernate.Cfg namespaces in the Using clause.
Now, the Data from Employee table is available as an Employee object.