Click here to Skip to main content
11,930,449 members (55,649 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked

Five reasons for using an O/R mapping tool

, 16 Mar 2005
Rate this:
Please Sign up or sign in to vote.
An O/R mapping tool generates persistence objects for your .NET application.


So, why should you use any O/R mapping tool? I am not talking about a specific tool but rather all O/R mapping tools in general. There are a number of reasons for using an O/R mapping tool but before I dive into that, let me give you a brief overview of what an O/R mapping tool really is.

An O/R mapping tool generates persistence objects for your .NET application. It is a modeling and code generation tool that connects to your database and reads its schema, then lets you map objects to database tables and views, specifies single-row insert, update, load, and delete operations, queries and stored procedure calls, as methods to these objects. And, it also lets you define one-to-one, one-to-many, many-to-one, and many-to-many relationships between objects based on relationships between tables in the database. It then generates fully working persistence objects code for you.

There are many other features that a good O/R mapping tool provides but I’m keeping my description brief so that I can talk more about the benefits.

Reason 1: Cuts down your development time

The first benefit of an O/R mapping tool is that it saves you a ton of development time (20% to 50% time depending on your situation). Now, O/R mapping tool is not generating any “rocket science” code for you and you could definitely do it manually if you wanted. But, that involves a lot of tedious work and you would definitely be happier if you didn’t have to do it yourself. Let’s do some simple math.

A typical application with 15-20 database tables has 30-50 objects (including domain and factory objects) and this is roughly 5000 to 10,000 lines of code. It is likely to take you a few weeks to a couple of months to develop and test this code. And, if your application has more tables than this (which many do), then just multiply the above numbers by that much.

On the other hand, an O/R Mapping tool would generate this code for you in a day or two. Even here, you need these 1-2 days primarily to determine your object mappings to the database. The actual code generation is instantaneous. So, your time saving is tremendous.

Reason 2: Produces better designed code

The second benefit of an O/R mapping tool is that it lets you produce better designed code than doing it yourself by-hand. I know what you’re thinking. You think you can do a better job than an O/R mapping tool because you write every aspect of your code. Some of you definitely can but not everyone. Consider this. An average development team has different levels of expertise and experience and not everybody is a good designer. As a result of this, they may not follow design patterns in their code and end up with a lesser quality code. And, if multiple developers are writing the code, their code is very likely going to be inconsistent with each other. And, inconsistency itself is a big source of poor quality in an application’s code.

On the other hand, a good O/R mapping tool uses code templates that have excellent design because they are designed and created by very senior (architect level) engineers. And, these code templates always follow known design patterns. So, the code that you’ll generate from an O/R mapping tool is very likely going to be better designed than the code designed by your own development team.

Reason 3: You don’t have to be a .NET expert

The third benefit of using an O/R mapping tool is that you don’t have to be a .NET expert to develop your persistence code. As you know, data access code is critical for the overall performance of your application. If this code is designed and developed poorly, it can severely affect your application. So, if you have developed this code by hand, you need to be an expert of .NET, COM+, stateless components, and MTS.

However, if you use an O/R mapping tool, you can focus primarily on the "logical design" of your persistence objects including object mapping and the different types of interactions with the database including insert, update, load, delete, queries, stored procedure calls, relationships, and more. And, the O/R mapping tool would do the rest for it. It would ensure that the generated code follows all the best practices of writing stateless .NET components to run in COM+ and MTS.

Reason 4: Saves you testing time

The fourth benefit of an O/R mapping tool is that it reduces your testing effort dramatically. If you had developed all the persistence code by hand, you would also be responsible for testing it yourself. And, as you know, testing requires as much effort as development in any project.

On the other hand, if you had generated code from an O/R mapping tool, it is coming from code templates that are thoroughly tested by the software vendor itself (more so than you because it is their primary focus). And, on top of it, hundreds or perhaps thousands of other customers are using this tool and have tested the code generated from this O/R mapping tool. As a result, many of the bugs that you might not find in your own testing have already been found and fixed in the generated code of an O/R mapping tool.

Reason 5: Simplifies your .NET development

If you have to write all the persistence code yourself, you’re bogged down into the details of ADO.NET, COM+, MTS, stateless .NET components, and more. And, you end up spending a lot of time for details that you really don’t need to. On the other hand, if you generate code from an O/R mapping tool, you get well design objects and you only need to deal with their public interface.

Below is an example of code you’ll write if you used an O/R mapping tool:

try { 
    Employees objInfo = new Employees();
    EmployeesFactory objFactory = new EmployeesFactory();
    objInfo.EmployeeID = EmployeeID; 
// code here to use the “objInfo” object 
catch(Exception ex) { 
    // code here to handle the exception 

As you can see, the generated code is very simple to use than actually writing the .NET components yourself.

Many people have never heard of O/R mapping tools and many have heard of them but are afraid to use them. I hope I have made a strong enough case here for you to give a serious consideration to O/R mapping for your project.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Iqbal M. Khan
Pakistan Pakistan
Iqbal Khan is the Director of Sales & Marketing at AlachiSoft (, a leading provider of O/R Mapping tool called TierDeveloper. You can reach him at

You may also be interested in...

Comments and Discussions

Questionyou don't reply to anyone?? Pin
Michael Sync5-Aug-07 17:14
memberMichael Sync5-Aug-07 17:14 
GeneralMain reason not to Pin
zarkon17-Mar-05 11:25
memberzarkon17-Mar-05 11:25 
GeneralRe: Main reason not to Pin
latticesoft13-Oct-05 12:29
susslatticesoft13-Oct-05 12:29 
GeneralI don't know Pin
WillemM17-Mar-05 10:22
memberWillemM17-Mar-05 10:22 
GeneralOpen Source OR mapping tools Pin
Martin Bohring16-Mar-05 22:45
memberMartin Bohring16-Mar-05 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 17 Mar 2005
Article Copyright 2005 by Iqbal M. Khan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid