Object Relational Mapping in ASP.NET 2.0
page 2 of 7
by Stephen Rylander
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 41414/ 56

OR Mappers

What is Object Relational mapping?  In a nutshell, it is a technique to provide automatic retrieval and persistence of data.  Usually this involves using a configuration file, often in XML, to map fields in your custom coded objects to fields and tables in a database.  In this way the OR Mapper can then take ownership of the best way to retrieve, update, insert and delete data and you can focus on building the application and not mess with the plumbing. 

Most professional developers use third-party components at some time and OR mapping products are an example of the acceptance and reliance on these types of components.  The reality of our work is that almost every application has to touch a database and this data access work is error prone, tedious and honestly, just plain boring after a while.  This type of work lends itself to mistakes.  I am reminded of the classic software developers axiom, “if you can reduce risk, then do so.”  This is one reason to use an OR mapper.

Another OR mapper advantage is the speed of development.  Using an OR mapper can drastically reduced the amount of code that needs to be written and debugged, plus it can quicken how you develop.  If you are mapping data directly to your objects, essentially making them entity objects, there is not data conversion between Datasets, data readers, structs or anything else.  This reduces the complexity and makes working with your data essentially the same as working with your objects.  Now your focus is on your domain model and not how ADO.NET is doing this or that task.  Please note that I am not saying that understanding ADO.NET is not important – you should understand these concepts to be a productive and knowledgeable developer – but now that you understand the core concepts you can step beyond it and really take advantage of this knowledge.

True OR mappers, which I consider different than code generators, do all their database access dynamically.  So, they are not generating files with code in them, and they are not using stored procedures.  In the .NET world, the mapper will do all its database access using parameterized queries, which as controversial as it may sound, are just as fast as stored procedures.  Thus, you now have the flexibility of dynamically generated SQL with the speed of a stored procedure.

Use of an OR mapper also provides a level of abstraction between your code libraries and the data source.  Let us say that you are using MS Access as your application data source and you are using an OR mapper.  You can now easily switch from MS Access to SQL Server 2005 without too much trouble because you do not have anything hard coded into your application that ties you to a platform.  Extrapolate this out and you can migrate from Oracle to SQL Server or Access to MySQL, or really any way you wish.

The biggest concept to understand here is that the OR Mapper is providing flexibility.  Flexibility in how you write your objects, flexibility in how you spend your development time and flexibility in what your data source is.  And of course, they are fast at the same time.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2023 ASPAlliance.com  |  Page Processed at 2023-03-22 4:06:05 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search