Stored procedures or OR mappers?

后端 未结 15 1265
天命终不由人
天命终不由人 2021-01-06 16:04

Which is better? Or use and OR mapper with SP\'s? If you have a system with SP\'s already, is an OR mapper worth it?

相关标签:
15条回答
  • 2021-01-06 17:01

    At my work, we mostly do line of business apps - contract work.

    For this type of business, I'm a huge fan of ORM. About four years ago (when the ORM tools were less mature) we studied up on CSLA and rolled our own simplified ORM tool that we use in most of our applications,including some enterprise-class systems that have 100+ tables.

    We estimate that this approach (which of course includes a lot of code generation) creates a time savings of up to 30% in our projects. Seriously, it's rediculous.

    There is a small performance trade-off, but it's insubstantial as long as you have a decent understanding of software development. There are always exceptions that require flexibility.

    For instance, extremely data-intensive batch operations should still be handled in specialized sprocs if possible. You probably don't want to send 100,000 huge records over the wire if you could do it in a sproc right on the database.

    This is the type of problem that newbie devs run into whether they're using ORM or not. They just have to see the results and if they're competent, they will get it.

    What we've seen in our web apps is that usually the most difficult to solve performance bottlenecks are no longer database-related even with ORM. Rather, tey're on the front-end (browser) due to bandwidth, AJAX overhead, etc. Even mid-range database servers are incredibly powerful these days.

    Of course, other shops who work on much larger high-demand systems may have different experiences there. :)

    0 讨论(0)
  • 2021-01-06 17:02

    Well the SP's are already there. It doesn't make sense to can them really. I guess does it make sense to use a mapper with SP's?

    0 讨论(0)
  • 2021-01-06 17:04

    I personally have found that SP's tend to be faster performance wise, at least for the large data items that I execute on a regular basis. But I know many people that swear by OR tools and wouldn't do ANYTHING else.

    0 讨论(0)
  • 2021-01-06 17:04

    I would argue that using an OR mapper will increase readability and maintainability of your applications source code, while using SP will increase the performance of the application.

    0 讨论(0)
  • 2021-01-06 17:04

    "I'm trying to drive in a nail. Should I use the heel of my shoe or a glass bottle?"

    Both Stored Procedures and ORMs are difficult and annoying to use for a developer (though not necessarily for a DBA or architect, respectively), because they incur a start-up cost and higher maintenance cost that doesn't guarantee a pay-off.

    Both will pay off well if the requirements aren't expected to change much over the lifespan of the system, but they will get in your way if you're building the system to discover the requirements in the first place.

    Straight-coded SQL or quasi-ORM like LINQ and ActiveRecord is better for build-to-discover projects (which happen in the enterprise a lot more than the PR wants you to think).

    Stored Procedures are better in a language-agnostic environment, or where fine-grained control over permissions is required. They're also better if your DBA has a better grasp of the requirements than your programmers.

    Full-blown ORMs are better if you do Big Design Up Front, use lots of UML, want to abstract the database back-end, and your architect has a better grasp of the requirements than either your DBA or programmers.

    And then there's option #4: Use all of them. A whole system is not usually just one program, and while many programs may talk to the same database, they could each use whatever method is appropriate both for the program's specific task, and for its level of maturity. That is: you start with straight-coded SQL or LINQ, then mature the program by refactoring in ORM and Stored Procedures where you see they make sense.

    0 讨论(0)
  • Stored procedures hands down. OR Mappers are language specific, and often add graphic slowdowns.

    Stored procedures means you're not limited by the language interface, and you can merely tack on new interfaces to the database in forwards compatible ways.

    My personal opinion of OR Mappers is their existence highlights a design flaw in the popular structure of databases. Database developers should realize the tasks people are trying to achieve with complicated OR-Mappers and create server-side utilities that assist in performing this task.

    OR Mappers also are epic targets of the "leaky abstraction" syndrome ( Joel On Software: Leaky Abstractions )

    Where its quite easy to find things it just cant handle because of the abstraction layer not being psychic.

    0 讨论(0)
提交回复
热议问题