In The craft
ORMs and Stored Procedures can Live together in Harmony
In a twitter conversation this morning I tried to drive the point that it’s better to use in, some cases, a stored procedure instead of an ORM.
To clarify, when I say I’m using an ORM, it means I am leaning on the ORM to generate the SQL for the problem I have described to the ORM via it’s API.
When I am using a stored procedure, I am rolling the SQL myself. It does not matter if I am calling it via the ORM or not, I’m still using a stored procedure.
The point I am making is some problems an ORM cannot handle well. Just the fact that an ORM is in the application and not in the database puts it at a disadvantage. With that said they do very well in 80 to 85 percent of the cases.
My point is simply that in some cases the ORM is the wrong tool for the job and a stored procedure is the right tool.