You really shouldn't write your own O/RM

time to read 2 min | 249 words

You do not have the resources to do as effectively as the existing tools in most scenarios. There is a reason that Nhibernate got over 100,000 Lines of Code. The simplest O/RM is just mapping from columns to properties. This is repetetive work that can be done by a code generation tool easily.

Then you realize that you need:

  • Transactions
  • Concurrency Control
  • Caching
  • Handling of associations between objects - This is a can of worms all by itself, there are quite a few of those, and you are likely to want to use all of them.

The above are the bare neccecities for an O/RM or a Data Mapper layer. I got problems with them because they are:

  1. Not trivial
  2. Solved problems

And then we didn't mentioned performance. I got a list of 25 bullet points of different (sometimes overlapping) features that I am using in NHibernate right now. None of them are esoteric by any mean. It's not a weekend project, not if you are going to do it right.