Friday, 20 August 2010

Object Relational Mapper

I use orm's quite extensively (mainly nHibernate and Llblgen) at work, and had been thinking about writing my own lightweight orm for many many months, and made a few attempts, none of which got fully completed, until last April, when during a week off i finally sat down collected all my ideas got rid of the complicated one's and wrote it.
I eventually went with a pure explicit engine, i have played (original 2 or 3 versions) with implicit, but after spending a great deal of time with nHibernate, honestly i have come to dislike and distrust implicit engines. I would prefer to say when i want an update, and when i request data, go back to the database to get it. Database developers (Ms, oracle or whoever) have spent more time than i ever could in optimising the query engines, so why on earth do i think i can do better? answer i can't, additionally if the engine decides when and what to write to the db as it feels like it there is risk it will get it wrong, and whats the point of persistance with that kind of risk.
Now i have a small amount of implicity in that it supports cascade (too useful to ignor) but i have restricted it a little, firstly if saving (insert or update) it will never delete, (otehrwise you have to track what queries the objects relate to etc) and it will check the record in the database if it needs to. Delete requests also cascade, and do delete, but only dependancies (i.e. if foreign keys to objects your deleting and fk column is not nullable the record is deleted). Finally at the point of calling write requests i have a cascade tree you can define, so you can specify exactly how deep to cascade if at all.

So why post about it now? well although i have been very happy with it, and my query engine is ok, i think it could be better, starting playing with a fluent Linq Expression qurery engine, my initial findins suggest i should be able to parse the expression nicely to fit in with the core engine, and would be a much nicer .net front end, I'll post my results when i actually get round to it (i have this next week off so may start it in a couple of days).

No comments:

Post a Comment