Introduction to N-hibernate

Introduction:
Hibernate 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 latest version of NHibernate can be downloaded from http://sourceforge.net/projects/nhibernate

Once you’ve downloaded and installed NHibernate, you’re ready to create a new solution and start using it.

 
Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment