Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convincing a die hard DBA to use an ORM for the majority of CRUD vs Stored Procedures, View, and Functions

I have been working with NHibernate, LINQ to SQL, and Entity Framework for quite some time. And while I see the benefits to using an ORM to keep the development effort moving quickly, the code simple, and the object relational impedance mismatch to a minimum, I still find it very difficult to convince a die hard SQL dba of an ORM's strengths. From my point of view an ORM can be used for at least 90-95% of all of your data access leaving those really hairy things to be done in procedures or functions where appropriate. I am by no means the guy that says we must do everything in the ORM!

Question: What are some of the better arguments for convincing an old school dba that the use of an ORM is not the absolute worst idea ever conceived by a programmer!

like image 647
Andrew Siemer Avatar asked Jul 27 '09 23:07

Andrew Siemer


People also ask

Is ORM better than stored procedure?

The bottom line is stored procedures using a DBMS's native SQL language can be orders of magnitude faster than ANY ORM generated SQL. However ORM approach is more maintainable. Most ORM devs are not experts at advanced SQL, and have no understanding/experience of this.

When and why would you use an ORM?

ORM is a technique that lets you query and manipulates data from a database using an object-oriented paradigm. It encapsulates the code needed to communicate with the database, so you don't use SQL anymore; you interact directly with an object in the same language you're using.

Why do people prefer ORM?

The most important reason to use an ORM is so that you can have a rich, object oriented business model and still be able to store it and write effective queries quickly against a relational database.

When should you avoid ORM?

If you know your data access pattern is going to be complex or you plan to use a lot of database-specific features, you may not want to use an ORM.


3 Answers

If you want to convince him, first you need to understand what his problem is with use of an ORM. Giving you a list of generic benefits is unlikely to help if it does not address the issues he has.

However, my first guess as to his issue would be that it prevents him from doing any optimisation because you're accessing tables directly so he has no layer of abstraction behind which to work, so if a table needs altering or (de)normalizing then he can't do it without breaking your application.

If you're wondering why a DBA would feel like this, and how to respond to it, then it's roughly the same as him coming up to you and saying he wants you to make all the private fields in your classes public, and that you can't change any of them without asking him first. Imagine what it would take for him to convince you that's a good idea, and then use the same argument on him.

like image 52
Greg Beech Avatar answered Nov 15 '22 23:11

Greg Beech


Explain to them that creating a stored procedure for every action taken by an application is unmaintainable on several levels.

  1. If the schema changes it's difficult to track down all the stored procedures that are affected.
  2. It's impossible ensure that multiple stored procedures aren't created to do the same thing, or if slightly altering an existing stored procedure is going to have serious ramifications.
  3. It's difficult to make sure that the application and database are in sync after a deploy.

Dynamic SQL has all these issues and more.

like image 43
Spencer Ruport Avatar answered Nov 16 '22 00:11

Spencer Ruport


I guess, my first question to "Convincing a die hard DBA to use an ORM" would be: Is the DBA also a programmer that also works outside the DB so that he/she would "use an ORM"? If not then why would the DBA give up a major part of their job to someone else and thereby significantly reduce their overall usefulness to the company? They wouldn't.

In any case, the best way to convince any engineer of anything is with empirical data. Setup a prototype with a few parts of the real application ported to ORM for the purpose of your demonstration and actually prove your points.

On another point I think you don't get the object relational impedance dilemma if you're trying to use that as an argument to use an Object-Relation-Mapper. The DBA could quote from that link you posted where where it says "Mapping such private object representation to database tables makes such databases fragile according to OOP philosophy" and that the issue is further pronounced "particularly when objects or class definitions are mapped (ORM) in a straightforward way to database tables or relational schemata" So according to your own link, by promoting ORM you are promoting the problem.

By using sprocs the DBA is free to make changes to the underlying schema, so long as the sproc still returns the same columns with the same types. Thusly with this abstraction that sprocs add, the direct schema mapping issues become nought. This does not mean however that you need to give up your beloved EF since EF can now be used quite happily with sprocs.

like image 26
StartupGuy Avatar answered Nov 16 '22 01:11

StartupGuy