NOTE: Read about our Current Status
A Brief Discussion on Object-Relational Mappers for .NET
"Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
Robert Heinlein, Time Enough For Love
If there's ever been one thing programmers have been good at since the dawn of computing, it's been figuring out how to make their jobs easier. Once certain patterns emerge, reusable code and components are soon to follow. In the case of code generation and O/R Mappers, sometimes the reusable code is used to generate more code.
As the role software plays in business becomes more important, the industrial-strength database platforms that used to live only within data centers have made their way out onto smaller, more personally manageable servers, and in some cases, on to desktop computers. Today the majority of all applications built use relational databases as their data storage mechanism. Thus, with the evolution of application development came the evolution of database drivers and the flurry of acronyms we see today, like ODBC, OLEDB, JDBC, DAO, RDO, and ADO. Although each of these database interaction libraries provides everything needed for applications to communicate with the database, they do little or nothing to help translate and persist the objects used by applications into SQL statements and data that can be stored by the relational databases. This work had to be done manually--meaning code had to be written by the programmer's hands every time.
For many years, developers repeatedly wrote the same data access layer code--methods called PersistChanges() or UpdateOrder(), which took actions such as building a SQL command to be sent to the database for processing, or updating a column value and having the database connectivity library handle the details of relaying that information to the database. There was very little variance among the actions taken by these types of methods that prompted programmers to consider building a general-purpose solution, something that could--with a little bit of information about the objects and data structure involved--automatically handle the tedium involved with CRUD (Create, Read, Update, Delete) operations. In the case of code generation, the idea is the same but, rather than a general purpose component, all of the code typically be written by hand is automatically generated based on database objects. It's just different sides of the same coin, you might say.
O/R Mappers and code generation started off with simple ideas and performed simple CRUD tasks easily. However, as these technologies have gained broader use, complexity has crept in. Most O/R Mappers on the market today have a special syntax to support specifying object criteria, such as a date range or ID value. Additionally, many O/R Mappers deal with a host of other concerns such as caching, concurrency, and validation, all of which are issues found in data access layer code.
Most database applications that use more than a handful of tables can benefit from O/R Mapping and code generation. The best way to determine if an O/R Mapper or code generation tool will help reduce your development costs is by taking a product for a spin and kicking the tires a bit. Although this guide will definitely help point you in the right direction, you should make an effort to evaluate products that interest you before settling on one in particular, which brings us to the topic of "how do I choose an O/R Mapper?"
What To Look For
Which O/R Mapper is best for you depends on your needs and preferences. Although there is a common level of functionality among almost every O/R Mapper, some provide more advanced features or can do code generation that the others do not. Some come with tools to help manage external configuration/mapping files, which may be important to you if you don't like editing files by hand. If price is an issue, you might take a closer look at the free components covered in this Guide. You may consider vendor support an important aspect of your purchase. Microsoft, the vendor of .NET itself, currently has an O/R Mapping framework named "ObjectSpaces" in development that, despite its delays, is aiming to provide developers with an O/R Mapping framework that will likely ship with a set of components packaged with Windows Vista upon its release. A little further in this Guide you will find a list of decision points that aim to provide you with a list of things to consider when evaluating an O/R Mapper for .NET.