Introduction to Object Relational Mapping (ORM) in .NET
Filed Under (Development, ORM) by fakhrul on 21-03-2009
Definition
By refering to the wikipedia, the Object Relational Mapping (ORM) is defined as
A programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools.
ORM is place between the database and the .NET object. For example, we have a class name as Student and the table name as TBL_STUDENT. The ORM are used to map the class Student and the TBL_STUDENT. There are 2 way to map the object and the table, one way is using the xml file, and other is using the .NET atrribute. In Nhibernate, I am using the attribute mapping because it is much easier.
Why you use it?
- You can apply the Domain Driven Design (DDD) easily.
- ORM generate the sql statement for you.
- It is price less. Free. There are a lot of open source for ORM.
- Support for multiple database. It’s flexible to change which DBMS you want to use. All setting is in the config files.
- Good performance. As you know, the ORM frameworks are develop from the expert all over the world. So you don’t worry about it. The only thing you need to worry is, how to use it. (Fortunately, almost all of the API was documented well.)
- The source code are provided (for open source ORM). You have the code and you can change it if you are need to do.
- Support are available. You can ask a question and discuss anything regarding to the ORM in the forum.
- Faster development process. Forget the learning curve because I think you only need not more than a week to know how to use it. Once you now, you will be suprise how fast it can be.
Last word
There are a lot of ORM framework for .NET. For example Spring.Net, NHibernate and Castle ActiveRecord. I had experience in using NHibernate and Castle ActiveRecord. Castle ActiveRecord is actually sit on top of NHibernate. It was build by a group of geek to simplify the use of NHibernate.
There are also a lot of tutorial and reference you can get from the internet. You can google it, the keyword is “ORM”, “NHibernate”, “Castle active record”.
Hope this post had give you an idea about the ORM. Thanks.
Other links
http://aspalliance.com/1069_Introducing_Object_Relational_Mapper.1
http://en.wikipedia.org/wiki/Object-relational_mapping












