NHibernate is a open source Object-Relational Mapping (ORM) tool. This ORM tool hides sql query complexities by replacing query with mapping and class object.
I already have article about basic NHibernate in previous post. If you are new to Nhibernate then I recommend to Click here Asp.Net & ORM Tool NHibernate For Dummy Tutorial – Select & Insert Operation first.
Lets recap what we have to do to work with NHibernate.
- Download necessary NHibernate file including NHibernate.dll & configuration template/example at http://sourceforge.net/projects/nhibernate
- Create xml mapping file and a class which representates DB table
- Include Nhibernate dll file, NHibernate xml configuration file, class library (if you have separate class project), and Asp.Net file it self
- Write codes inside the Asp.Net file that contains NHibernate configuration class object initialization, AddAssembly to Class Library, BuildSessionFactory, OpenSession, BeginTransaction, SaveOrUpdate, Commit to save data to DB.
- Write SQL Query replacement with QueryOver<T>() method and Where filter (if necessary) that has LinQ like syntax to retrieve record(s) and automatically convert to a class