views:

282

answers:

3

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!

+3  A: 

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.

Spencer Ruport
One guy that I worked with says "we should use stored procedures to isolate the dependent applications from change". Then he changed what the stored procedure returned to one of my applications and broke it! Eh?
Andrew Siemer
If you use a DB project such as the ones in VS2008 then it actually compiles the database and will warn you of any errors due to schema changes (e.g. accessing changed columns etc.), so your point 1 is invalid. Similarly point 2 is invalid assuming somebody is in charge of the DB and won't let crap in. And 3 is negated by having a proper automated deployment. So I don't really buy any of these arguments.
Greg Beech
Unless your team using a DB other than SQL Server, in which case using a DB project in VS2008 is not an option for you. Then those points make perfect sense.
Justin R.
+3  A: 

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.

Greg Beech
I like your perspective. However, the thing that I have never understood is why DBA's and programmers are not "on the same team". Why is that most of the places I work have DBA's and developers roped off from one another when their duties over lap SOOO much. In the case you make for optimization - the standard way around this is to ORM everything (99%?), identify needs for optimiztion, and port the query to a proc where needed. But in most cases I find ORMs generate great SQL!
Andrew Siemer
We all work together ad have no friction at all. But you have to understand the difference in roles. DBAs are responsible for keeping the databases running, backed up, and performing correctly. If the DB operations are slow because the table structure is wrong, and needs altering, then who gets the blame when it can't be fixed? The DBA. But he can't do anything about it because people are accessing the tables directly. That's one reason why many of them are rather against direct table access.
Greg Beech
+1  A: 

Procedures used to be more efficient because of predictable caching mechanisms. However, many DBA's overkill the procedures, introducing lots of branching logic with IF commands, resulting in an scenarios where they become uncacheable.

Next, procedures are only useful if you plan to span data logic across multiple platforms; a website and separate client application, for example. If you're only making a web application, the procedures introduce an unnecessary level of abstraction and more things to juggle. Having to adjust a table, then a procedure, then a data model is a lot of work when adjusting a single model via the ORM would suffice.

Lastly, procedures couple your code to your database very tightly. If you want to migrate to a different database you have to migrate all the procedures, some of which may need to be heavily rewritten. This sort of migration is significantly easier with an ORM since you can yank out the backend and install a new one without the frontend application knowing the difference.

Soviut
@Soviut while I totally agree with the logic you present...I have to admit that in all the places I have been I have never swapped out my SQL Server for an Oracle server...or MySQL. I have heard this argument for ORM so many times but have never actually been somewhere that justified it! +1 any how!
Andrew Siemer
I agree this doesn't happen often. However, swappable backends are basically free when you're using an ORM that supports them. I guess my point was really that procedures tightly couple and ORMs decouple.
Soviut