7

Let's say you're in an IT shop that allows no ORM tool of any kind. They don't want to buy one, and neither can you use an open source solution.

What would you do? Give up on a real domain model and work table-centric? Craft own DAL?

Robert S.
  • 25,266
  • 14
  • 84
  • 116
  • I'm just interested - what is the reason for not allowing ORM to be used? – Ree Mar 05 '09 at 18:50
  • I've made a similar decree in the past, yes there are a lot of plus's to ORM, but ORM's like the ActiveRecord pattern can be efficient and lead to resource abusive queries or complete losses of efficiency. – David Mar 05 '09 at 18:53
  • I'm guessing they don't want to use something that isn't supported, but they also don't want to pony up for a commercial solution. – Adam Jaskiewicz Mar 05 '09 at 18:54
  • @David - I recognize that there are valid reasons not to use an ORM, but setting a firm "no ORMs allowed at all" rule is a bad idea unless you have a really, really, really good reason. – Jason Baker Mar 05 '09 at 19:15
  • Java Hibernate adds something like 60 seconds to startup time. Whenever I use ORM it's tempting to spend way too much time trying to do things "the ORM way" even if "the SQL way" would be easier. We need more information. How much does your boss know about ORM? How much do you know? – joeforker Mar 05 '09 at 19:16

14 Answers14

12

Strictly speaking your options are:

  1. Don't use a relational database
  2. Don't use an OOP language

Otherwise some kind of ORM solution is inevitable (even if you roll your own, its still a simple ORM layer).

Dr. Mike Hopper
  • 802
  • 1
  • 8
  • 19
  • 3
    You are sooooo right!!! The O in ORM is the first O in OOP. The R in ORM is the first R in RDBMS. And the M is the mapping. – Andrei Rînea Mar 06 '09 at 00:34
9

Options:

  1. Roll your own
  2. Quit
  3. Use an open source one anyway without telling them, show them the prototype when it's working well, then ask them to reconsider open source.
Chris Doggett
  • 19,959
  • 4
  • 61
  • 86
9

Based on your username, I'd say "use LINQ." It's built into .NET and it's not an ORM (strictly speaking).

Robert S.
  • 25,266
  • 14
  • 84
  • 116
6

If you truly cannot use one of the existing ORMs, then I do not advise creating your own. Locally grown ORMs tend to be half-implemented, poorly-designed, wart-ridden beasts that appear to help for the first six months, then gradually become the biggest time-sucks on the project.

You can do without an ORM if you apply patterns like "RowDataGateway" or "TableDataGateway" from Fowler's Patterns of Enterprise Application Architecture.

You'll still end up growing your own isolation layer to separate your domain from the database, but it won't be as expensive to create as rolling your own ORM.

5

There are three possibilities here:

  1. Your bosses don't understand the benefits of using an ORM.
  2. Your bosses are doing things the way they always have done things and won't consider changing.
  3. Your bosses have valid reasons for not choosing an ORM.

More than likely though, it's a combination of these three things. They probably have valid concerns that could be cured through better understanding of ORMs. My advice is to try selling them on ORMs. Find a particularly nasty piece of code that could be cured by using an ORM and make a prototype that shows how much that code could be simplified. Also, be willing to compromise.

If they're not willing to budge on this, you need to ask yourself if this is really a place you want to work. Not because they won't let you use ORMs (which you could probably live without), but because they won't listen to you. You can't always have your way, but you should have input on the development process.

Jason Baker
  • 192,085
  • 135
  • 376
  • 510
4

I'd roll my own DAL, using something along the lines of Generic DAOs to abstract it in such a way that the rest of my code isn't tightly coupled with however I'm getting to the data.

That makes it easy to swap it all over to an ORM if they come around later.

Adam Jaskiewicz
  • 10,934
  • 3
  • 34
  • 37
4

If it's about the company being too cheap to buy one, then write your own, and at the end of the project show them the cost in terms of your time. (I assume they're against free alternatives on principle)

If it's about performance, you might have to check whether they have a point.

If they worry that it adds a layer of complexity which other developers will have to learn, then show some examples of code simplified with the ORM.

If it's because the application is already very "table-centric" you'll also have to think whether adding an ORM will improve things or just add a lot of unnecessary mapping complexity.

(Oh, and read this : http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx )

interstar
  • 26,048
  • 36
  • 112
  • 180
3

Craft your own DAL, like we did in the beforetime, the long long ago... 2004.

Greg Hurlman
  • 17,666
  • 6
  • 54
  • 86
  • I don't think that's a very good argument. I'm guessing that you also advocate using .Net 1.1 like we did in 2004? – Jason Baker Mar 05 '09 at 19:14
  • 1
    It is common sense; if you can't use a off the shelf tool, write your own. good programming practices shouldn't be limited to what tools you have. Tools save time and money, but if you can't have them don't do things badly or quit to retaliate. – MrChrister Mar 05 '09 at 19:21
  • @Jason - If you've been told that you can't use .Net 2.0 and above, yes, I would expect that. – Greg Hurlman Mar 06 '09 at 14:50
2

First off, it's absolutely retarded that you can't even use an open source one.

If you have to roll your own, it's not a huge deal. You can still have domain models just fine. You might have an easier time if you model each record, and then build the domain models to load data from that as an intermediate format.

Saem
  • 3,403
  • 23
  • 12
1

See what they think about iBatis (http://ibatis.apache.org/) which isn't an ORM but helps you get objects from database queries without inscrutable ORM magic, lots of XML though.

How are they doing things now?

joeforker
  • 40,459
  • 37
  • 151
  • 246
1

I would roll my own solution, probably using some kind of code generation tool. Tecnically if you translate the results (be it datareaders, tables, recordset or whatever) to your objects you have a small o/r mapper, very lacking but still... It is a matter of definition I guess.

My primary goal would be to avoid repeating CRUD in my code, it takes time, is boring and is a source of defects.

As stated: if a relational database is not required you could always go with some object database. But thoose are far more uncommon and if your boss is against orm:s he is unlikely to go for that.

Jon
  • 561
  • 4
  • 14
0

If you decide to build our own DAL, Davy Brion has a quite good tutorial for that.
Take a look at the Build Your Own Data Access Layer Series.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
0

Ask why ORM's are not allowed, what constitutes as a ORM, and then decide from there 1 of two possibilities:

  1. Deal
  2. No deal ( quit )
David
  • 17,673
  • 10
  • 68
  • 97
  • I think 2 would be funnier if it said "No deal" – Powerlord Mar 05 '09 at 18:57
  • I agree with your opinion and fixed it. – David Mar 05 '09 at 19:02
  • 2
    Isn't quitting over this a little childish? Create your own if you are a programmer. – MrChrister Mar 05 '09 at 19:07
  • @MrChrister The question appears to state no ORM is allowed... so whats the difference of writing your own and using an open source solution? Plus writing your own ORM increases the likelihood of bugs and loss of a larger peer reviewed code construct. – David Mar 05 '09 at 19:46
  • @David - the one thing we know is the project requires data access. Of course it will have bugs, and I didn't say release it to the world. Make work for this project, if it is hard to support, then the code wasn't good. – MrChrister Mar 05 '09 at 19:49
  • @MrChrister I think we've reached one of those differences of opinion points that doesn't end well, I'll agree to disagree with you :) – David Mar 05 '09 at 20:39
-4

"no ORM tool of any kind. They don't want to buy one, and neither can you use an open source solution."

No ORM any kind OR just open source/$$$?

There are free versions of great ORM tools:

boj
  • 10,935
  • 5
  • 38
  • 57
  • I've read not only the question but the first line too. I feel some conflict in the first two sentences. "No ORM any kind" OR just no "open source or buy one"? Maybe he can use a non-open source but free ORM. – boj Mar 05 '09 at 20:06