tags:

views:

2391

answers:

14

If you were to motivate the "pros" of why you would use an ORM to management/client, what would the reasons be?

Try and keep one reason per answer so that we can see what gets voted up as the best reasons

A: 

no extra sql.

Great brand new applications

no extra sql.

l_39217_l
+2  A: 

To minimise duplication of simple SQL queries.

Tim Wardle
+19  A: 

Speeding development. For example, eliminating repetitive code like mapping query result fields to object members and vice-versa.

Bill Karwin
+18  A: 

Making data access more abstract and portable. ORM implementation classes know how to write vendor-specific SQL, so you don't have to.

Bill Karwin
While I agree that this is a feature of ORM's, I'd propose that the use-case is fairly limited. I have never really used anything but MySql and sqlite for about a decade. I think it's probably a very rare requirement for most developers.
troelskn
@troelskn: I agree, I have used many RDBMS products, but never more than one or two per project. So portability isn't the most practical value of abstracting SQL. I think many ORM users simply want to avoid coding in SQL at all.
Bill Karwin
vendors come out with new versions/features all the time...just need some cool people to write the dialect and easy upgrade it is!
dotjoe
+2  A: 

So that your object model and persistence model match.

cletus
Maybe so that your persistence is transparent to your object model
S.Lott
+7  A: 

Supporting OO encapsulation of business rules in your data access layer. You can write (and debug) business rules in your application language of preference, instead of clunky trigger and stored procedure languages.

Bill Karwin
A: 

.net tiers using code smith templates

http://nettiers.com/default.aspx?AspxAutoDetectCookieSupport=1

Why code something that can be generated just as well.

Jobo
+3  A: 

The reason I'm looking into it is to avoid the generated code from VS2005's DAL tools (schema mapping, TableAdapters).

The DAL/BLL i created over a year ago was working fine (for what I had built it for) until someone else started using it to take advantage of some of the generated functions (which I had no idea were there)

It looks like it will provide a much more intuitive and cleaner solution than the DAL/BLL solution from http://wwww.asp.net

I was thinking about created my own SQL Command C# DAL code generator, but the ORM looks like a more elegant solution

phsr
A: 

This blog post by Glenn Block should help.

Happy Coding !

Perpetualcoder
+3  A: 

Generating boilerplate code for basic CRUD operations. Some ORM frameworks can inspect database metadata directly, read metadata mapping files, or use declarative class properties.

Bill Karwin
A: 

convince them how much time / money you will save when changes come in and you don't have to rewrite your SQL since the ORM tool will do that for you

zmf
+1  A: 

You can move to different database software easily because you are developing to an abstraction.

MattF
In 30 plus years of doing datbase work, I have not once had to do this.
HLGEM
Doesn't mean it's not possible! :)
MattF
@HLGEM it means you're closing the choices for the client. It could actually happen, in only 3 years of webapps work, we've built portable software using ORMs
Alfabravo
A: 

Abstract the sql away 95% of the time so not everyone on the team needs to know how to write super efficient database specific queries.

Jared
+7  A: 

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. From my viewpoint, I don't see any real advantages that a good ORM gives you when compared with other generated DAL's other than the advanced types of queries you can write.

One type of query I am thinking of is a polymorphic query. A simple ORM query might select all shapes in your database. You get a collection of shapes back. But each instance is a square, circle or rectangle according to its discriminator.

Another type of query would be one that eagerly fetches an object and one or more related objects or collections in a single database call. e.g. Each shape object is returned with its vertex and side collections populated.

I'm sorry to disagree with so many others here, but I don't think that code generation is a good enough reason by itself to go with an ORM. You can write or find many good DAL templates for code generators that do not have the conceptual or performance overhead that ORM's do.

Or, if you think that you don't need to know how to write good SQL to use an ORM, again, I disagree. It might be true that from the perspective of writing single queries, relying on an ORM is easier. But, with ORM's it is far too easy to create poor performing routines when developers don't understand how their queries work with the ORM and the SQL they translate into.

Having a data layer that works against multiple databases can be a benefit. It's not one that I have had to rely on that often though.

In the end, I have to reiterate that in my experience, if you are not using the more advanced query features of your ORM, there are other options that solve the remaining problems with less learning and fewer CPU cycles.

Oh yeah, some developers do find working with ORM's to be fun so ORM's are also good from the keep-your-developers-happy perspective. =)

Chuck