Please enable Javascript to correctly display the contents on Dot Net Tricks!

Introduction to N-hibernate

  Author : Shailendra Chauhan
Updated On : 16 Jul 2013
Total Views : 19,189   
 

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 automatically translates our programming language syntax to a language that the database understands. NHibernate also generates the required SQL statements to fetch, insert, update and delete 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.

What is O/RM?

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 an O/RM is the mapping. Basically mapping technique binds the object and relational worlds. By mapping, we 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 engine to build SQL code to retrieve data and transforms it into objects. 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.

Why NHibernate?

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".

Installing NHibernate

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:

  1. The latest version of NHibernate can be downloaded from http://sourceforge.net/projects/nhibernate

  2. NHibernate meta blog at http://nhforge.org/blogs/nhibernate

  3. Fabio Maulo's blog at http://fabiomaulo.blogspot.com Fabio is the leader of the NHibernate project.

  4. 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.

YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
11 DEC
ASP.NET MVC with AngularJS Development (offline)

Sat-Sun 09:30 AM-11:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (11:00 AM-12:30 PM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+