R – What ORM would you choose for working with legacy databases

legacy-databasenetorm

I am in the process of integrating a number of legacy systems. They each have different databases; and I will need to write data access code for most of them.

The database schemas cannot be changed (I might be able to apply some indexes and such, but tables and their columns must retain the structure). Some of the databases has an OK design, with appropiate relationsships and primary / foreign keys, and some of the other databases lacks that very much.

Which ORM would you choose for this task ? I would like to use the same ORM accross the project; and my requirements are:

  • Ability to rename tables or columns in code; but retain the old name in the database.
  • Reasonable code generation
  • Efficient LINQ support (LINQ queries against the data model should be translated to efficient SQL).
  • Generated data classes should preferably be POCO's.
  • Preferably support for different database engines.

I currently have the most experience with LINQ-To-SQL; but I have a feeling it might be the wrong choice for this project. I am willing to invest some time in learning a new framework.

Best Answer

At a guess, I think an ORM might cause you more trouble than it saves. If you have several different legacy databases where some of them are poorly designed, you might find it easier to build the data access layer at a lower level than an ORM. Fowler's Patterns of Enterprise Application Architecture does quite a good job of cataloguing various approaches to structuring data access layers.

Some of the data access layer might be amenable to a code generation solution; however the presence of a variety of schemas (some messy as you say) suggests that a one-size-fits-all approach may not work, or may involve disproportionate effort to make it play nicely with all of the legacy databases.