ORMs are awful.. long live ORMS!

Home / ORMs are awful.. long live ORMS!

Recently, I had a conversation with another developer about the role of DBA’s in the development process. It was immediately clear that, philosophically, our viewpoints diverged.

The conversation digressed, and I found that this developer was completely against using ORMs to make queries. The term ‘ad-hoc queries’ was bandied about quite a bit. This other developer also went so far as to tell me that, in a code review in ‘hard-core’ dev shops, ad-hoc queries would get smacked down.

This seemed really curious to me. I’ve been a big fan of ORMs and generating queries from with code dynamically for quite some time. Domain-driven design almost necessitates code-based querying. I’ve used LLBGen, NHibernate, and EF. LINQ generation of queries is probably the single best feature in .NET that endears me to Microsoft technologies.

Having said that though, this other developer’s rationale was not without merit. He cited that sprocs were the way to go due to predictability. I can see that to an extent Additionally, DBA’s could do their jobs better. For example, if a query performed poorly, the schema could be updated without any code changes. While I could appreciate the arguments, I’m still not convinced and don’t really think that dynamic, code-driven, queries are a bad thing.

The reality is that if queries are performing basic CRUD operations with little or no logic, is there value in writing a sproc for every operation? It doesn’t seem that way to me. If we completely eliminate the use of LINQ Expressions, Binary Trees, and Delegates, our code has now become very rigid. Also, does the sproc add anything in terms of performance? In basic CRUD scenarios, I have seen no evidence to indicate a performance benefit.

Given the choice, I would go with using an ORM and LINQ-based queries due to the flexibility it affords. Being able to query against any column with pagination (with .Skip().Take()) makes querying the data that drives an application extremely straight-forward.

At any rate, I’m open to either approach. Everyone must walk the tight-rope of balancing between strong ideas that, should be, loosely held.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.