<p>I'm toying with the idea of phasing in an ORM into an application I support. The app is not very structured with no unit tests. So any change will be risky. I'm obviously concerned that I've got a good enough reason to change. The idea is that there will be less boiler plate code for data access and there for greater productivity.</p>

<p>Do this ring true with your experiences?<br>
Is it possible or even a good idea to phase it in?<br>
What are the downsides of an ORM?</p>

[{'answer_id': 22014, 'author': 'svrist', 'author_id': 86, 'author_profile': 'https://Stackoverflow.com/users/86', 'pm_score': 0, 'selected': False, 'text': '<p>The rule for refactoring is. Do unit tests.</p>\n\n<p>So maybe first you should place some unittests at least for the core/major things.</p>\n\n<p>The ORM should be designed for decreasing boilerplate code. The time/trouble vs. ROI to be enterprisy is up to you to estimate :)</p>\n'}, {'answer_id': 22018, 'author': 'FantaMango77', 'author_id': 2374, 'author_profile': 'https://Stackoverflow.com/users/2374', 'pm_score': 0, 'selected': False, 'text': '<p>I heard that TypeMock is often being used to refactor legacy code.</p>\n'}, {'answer_id': 22044, 'author': 'Ian Nelson', 'author_id': 2084, 'author_profile': 'https://Stackoverflow.com/users/2084', 'pm_score': 3, 'selected': True, 'text': '<p>I would strongly recommend getting a copy of Michael Feather\'s book <a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="nofollow noreferrer" rel="nofollow noreferrer">Working Effectively With Legacy Code</a> (by "Legacy Code" Feathers means any system that isn\'t adequately covered by unit tests). It is full of good ideas which should help you with your refactoring and phasing in of best practices.</p>\n\n<p>Sure, you could phase in the introduction of an ORM, initially using it for accessing some subset of your domain model. And yes, I have found that use of an ORM speeds up development time - this is one of the key benefits and I certainly don\'t miss the days when I used to laboriously hand-craft data access layers.</p>\n\n<p>Downsides of ORM - from experience, there is inevitably a bit of a learning curve in getting to grips with the concepts, configuration and idiosyncracies of the chosen ORM solution.</p>\n\n<p><em>Edit: corrected author\'s name</em></p>\n'}, {'answer_id': 22053, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 0, 'selected': False, 'text': '<p>I seriously think introducing ORM into a legacy application is calling for trouble (and might be the same amount of trouble as a complete rewrite).</p>\n\n<p>Other than that, ORM is a great way to go, and should definitely by considered.</p>\n'}, {'answer_id': 22066, 'author': 'Allain Lalonde', 'author_id': 2443, 'author_profile': 'https://Stackoverflow.com/users/2443', 'pm_score': 0, 'selected': False, 'text': '<p>Unless your code is already architectured to allow for "hot swapping" of your model layer backend, changing it in any way will always be extremely risky.  </p>\n\n<p>Trying to build a safety net of unit tests on poorly architected code isn\'t going to guarantee success, only make you feel safer about changing it.</p>\n\n<p>So, unless you have a strong business case for taking on the risks involved it\'s probably best to leave well enough alone.</p>\n'}, {'answer_id': 22139, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I work on a large ASP.net application where we recently started to use NHibernate. We moved a large number of domain objects that we had been persisting manually to Sql Server over to NHibernate instead. It simplified things quite a bit and made it much easier to change things over time. We're glad we made the changes and are using NHibernate where appropriate for a lot of our new work. </p>\n"}, {'answer_id': 22216, 'author': 'Mike Woodhouse', 'author_id': 1060, 'author_profile': 'https://Stackoverflow.com/users/1060', 'pm_score': 2, 'selected': False, 'text': '<p>The "Robert C Martin" book, which was actually written by Michael Feathers ("Uncle Bob" is, it seems, a brand name these days!) is a must.</p>\n\n<p>It\'s near-impossible - not to mention insanely time-consuming - to put unit tests into an application not developed with them. The code just won\'t be amenable.</p>\n\n<p>But that\'s not a problem. Refactoring is about changing design without changing function (I hope I haven\'t corrupted the meaning too badly there) so you can work in a much broader fashion. </p>\n\n<p>Start out with big chunks. Set up a repeatable execution, and capture what happens as the expected result for subsequent executions. Now you have your app, or part of it at least, under test. Not a very good or comprehensive test, sure, but it\'s a start and things can only get better from there.</p>\n\n<p>Now you can start to refactor. You want to start extracting your data access code so that it can be replaced with ORM functionality without disturbing too much. Test often: with legacy apps you\'ll be surprised what breaks; cohesion and coupling are seldom what they might be.</p>\n\n<p>I\'d also consider looking at Martin Fowler\'s <a href="https://rads.stackoverflow.com/amzn/click/com/0201485672" rel="nofollow noreferrer" rel="nofollow noreferrer">Refactoring</a>, which is, obviously enough, the definitive work on the process.</p>\n'}]
['https://Stackoverflow.com/questions/22011', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1116/']