NHibernate is a .NET based object persistence library for relational databases. Basically it is a framework that allows us to talk to a relational database in an object-oriented way. We can store/persist objects in a database and load those objects from the database later on. NHibernate "auto-magically" translates our object-based language to a language that the database understands. That is, NHibernate generates the necessary SQL statements for us to insert, update, delete, and load data.
If we use NHibernate, then we never have to write any code that deals with the fact that there is an impedance mismatch between the way we develop applications in .NET and how a database works. NHibernate has abstracted away this mismatch for us.
O/RM is an acronym that stands for object/relational mapping. In a nutshell, an O/RM framework is used to persist model objects in a relational database and retrieve them. It uses metadata information to interface with the database. This way, your data-layer code knows nothing about the database structure; the O/RM tool becomes middleware that completely hides the complexity.
The heart of O/RM is the mapping—the mapping technique is what binds the object and relational worlds. By mapping, you express how a class and its properties are related to one or more tables in the database. This information is used by the O/RM tool’s engine to dynamically build SQL code that retrieves data and transforms it into objects. Similarly, by tracking changes to objects’ properties, it can use mapping data to send updates back to the database. The mapping information is generally expressed as an XML file. As an alternative, some O/RM tools use attributes on the classes and their properties to maintain mapping data.
In the past, we carefully hand-crafted our data access layers for the applications we wrote. We spent as much as 50% or more of our overall time to implement and maintain this data layer.It was not a very challenging task though, and a lot of repetitive coding was involved.
As we were not the only developers facing the problem of writing the data access code,some people started to write and publish a framework that would solve this problem. This was the birth of the ORM frameworks such as NHibernate. Nowadays, accessing relational data from an object-oriented application is a solved problem
Thus, writing your own data layer is a waste of time. Somebody even used a much more pronounced phrase to pinpoint this fact, "Writing your own data access layer is like stealing money from your client".
NHibernate is an open source project (OSS). Thus, the code and/or the binaries are freely available and can be downloaded from SourceForge. Before you can start coding, you must first install NHibernate. The following list presents a couple of blogs that are either mostly dedicated to NHibernate or contain a lot of information around this framework:
The latest version of NHibernate can be downloaded from http://sourceforge.net/projects/nhibernate/
NHibernate meta blog at http://nhforge.org/blogs/nhibernat
NHibernate FAQs at http://nhibernate.hibernatingrhinos.com/
Fabio Maulo's blog at http://fabiomaulo.blogspot.com. Fabio is the leader of the NHibernate project.
James Gregory's blog at http://jagregory.com. James is the leader of the Fluent NHibernate project.
Once you’ve downloaded and installed NHibernate, you’re ready to create a new solution and start using it.