Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. To ORM or not to ORM

To ORM or not to ORM

Scheduled Pinned Locked Moved The Lounge
databaseperformancecsharppostgresql
75 Posts 31 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    PIEBALDconsult wrote:

    However, I have worked with a database system that ignored order of operations but was faaaassssttt. :(

    Dirty reads, same problem.

    PIEBALDconsult wrote:

    Though I don't think this matters to this discussion.

    Same goes for code; do you want a solution fast, or do you want a solution that is good? I can see how I'd use an ORM for prototyping, but would prefer an actual query in production.

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #13

    I enjoy a good dirty read. :~

    1 Reply Last reply
    0
    • R RickZeeland

      At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #14

      I'm curious -- are you doing anything with the database other than presenting it to the UI so the user can CRUD the data? As in, do you have actually have any business logic that actually does something internally with the data?

      Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      R J 2 Replies Last reply
      0
      • R RickZeeland

        At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #15

        Slacker may have the right of it, most of us old farts despise ORM products probably because we have all rolled our own which we therefore know inside out and most of the ORMs are way too complex. I inherited ClassBuilder from a senior developer in the 90s, written in VB5, the current version (in c#) is basically the same. It does a hell of a lot less than commercial ORMS and it does a hell of a lot more of what I use every day.

        Never underestimate the power of human stupidity RAH

        P 1 Reply Last reply
        0
        • R RickZeeland

          At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

          J Offline
          J Offline
          jesarg
          wrote on last edited by
          #16

          Use ORM's to broaden your development skills and advance your career. But don't expect to be more productive in all scenarios (sometimes the opposite happens).

          1 Reply Last reply
          0
          • R RickZeeland

            At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

            abmvA Offline
            abmvA Offline
            abmv
            wrote on last edited by
            #17

            From a maintenance perspective using ORM relieves the developers from maintaining at the database level. You could develop all your core and business logic in code and cover all the test cases and have the need not to debug at the database level.It would be a good choice.

            Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

            We are in the beginning of a mass extinction. - Greta Thunberg

            1 Reply Last reply
            0
            • R RickZeeland

              At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

              D Offline
              D Offline
              Duncan Edwards Jones
              wrote on last edited by
              #18

              My advice would be to use an ORM (probably EF even though faster ones do exist) but keep a close eye on what the ORM is doing and learn how to performance tune it - in particular when not to use lazy loading. ( This is based on the economics of developer time being staggeringly expensive and hardware spectacularly cheap - if that does not apply in your situation then adjust accordingly. )

              J 1 Reply Last reply
              0
              • D Duncan Edwards Jones

                My advice would be to use an ORM (probably EF even though faster ones do exist) but keep a close eye on what the ORM is doing and learn how to performance tune it - in particular when not to use lazy loading. ( This is based on the economics of developer time being staggeringly expensive and hardware spectacularly cheap - if that does not apply in your situation then adjust accordingly. )

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #19

                Duncan Edwards Jones wrote:

                in particular when not to use lazy loading.

                Hear hear

                Wrong is evil and must be defeated. - Jeff Ello

                1 Reply Last reply
                0
                • M Mycroft Holmes

                  Slacker may have the right of it, most of us old farts despise ORM products probably because we have all rolled our own which we therefore know inside out and most of the ORMs are way too complex. I inherited ClassBuilder from a senior developer in the 90s, written in VB5, the current version (in c#) is basically the same. It does a hell of a lot less than commercial ORMS and it does a hell of a lot more of what I use every day.

                  Never underestimate the power of human stupidity RAH

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #20

                  Mycroft Holmes wrote:

                  Slacker may have the right of it, most of us old farts despise ORM products

                  Don't forget that the ORM crowd still need their programming training wheels; they learn how to do bare metal SQL coding when they get their "big boy pants" ;)

                  This space for rent

                  S 1 Reply Last reply
                  0
                  • L Lost User

                    Well, if the collegue can explain the added value of the extra dependency and the added complexity, then yes. And all software-shops claim that performance is an important factor, but no-one dies if a manager has to wait a second longer for a loop to complete. Being correct is more important than being quick :thumbsup:

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    R Offline
                    R Offline
                    RickZeeland
                    wrote on last edited by
                    #21

                    Well, if I understood him correctly he meant to reduce complexity and make programming more simple. I have to disagree on the performance point you make though, in the past the application he is working on proved to be problematic due to the massive amount of queries, this was one of the reasons to opt for PostgreSQL instead of SQL Server which we used before. SQL Server really struggled where PostgreSQL runs without any problems.

                    J L 2 Replies Last reply
                    0
                    • C CodeWraith

                      RickZeeland wrote:

                      started using NHibernate

                      There's the problem. He has not yet hit a bump in the road and desperately searched the documentation (which always used to be incomplete) for a solution. The learning curve is steep enough, even if you don't have to pray that the better (Java) Hibernate documentation also applies to your current NHibernate version. The number of tables is not the problem, the number of rows in those tables could be. NHibernate used to be a memory hog and I had to throw it out of a project only days before the deadline because of that. Also, I had to use an existing database and NHibernate kept preaching about good and bad practices and it will not shut the *elephant* up. What else would one expect of something that comes from the Java corner? Don't use it if you are not a masochist.

                      I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                      R Offline
                      R Offline
                      RickZeeland
                      wrote on last edited by
                      #22

                      Thanks for pointing that out, that seems to confirm my gut feeling, I already read a similar comment about the NHibernate documentation in a review of ORM's, the author did not even consider testing NHibernate as he could not make head or tails from the documentation !

                      1 Reply Last reply
                      0
                      • R RickZeeland

                        At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

                        J Offline
                        J Offline
                        Jorgen Andersson
                        wrote on last edited by
                        #23

                        Twenty tables, why bother? Sounds like changing for the sake of changing. If it was a new project, and mostly CRUD I'd go EF. Otherwise I'd handcrank it or use a lightweight micro-ORM. If performance is an issue of any kind whatsoever, don't do NHibernate. Here's[^] some benchmarks by Frans Bouma (of llblgen). Here's[^] an updated version the code he used. Take a look at the code and test for yourself.

                        Wrong is evil and must be defeated. - Jeff Ello

                        R 1 Reply Last reply
                        0
                        • P Pete OHanlon

                          I first used ORMs about 20 years ago. I have been saddled with trying out various ones over the intervening years. My advice, if you have to go ORM, roll your own because at least then it might do what you want and not get in the way.

                          This space for rent

                          R Offline
                          R Offline
                          RickZeeland
                          wrote on last edited by
                          #24

                          Thanks, that seems to confirm my gut feeling.

                          1 Reply Last reply
                          0
                          • S Slacker007

                            ORM. Most old farts have no clue how to ORM, therefore they advise against it. Don't be like that. I have been working on enterprise apps for a long time with ORM and no issues. Do it right, and it will handle itself. Performance is not an issue when done correctly. Edit: do note, that for most application transactions (web and non-web), ORM will be just fine. I wouldn't use ORM for ETL, or big data load stuff.

                            R Offline
                            R Offline
                            RickZeeland
                            wrote on last edited by
                            #25

                            Thanks, I'm afraid I'm one of those old farts haha :-\ Still I get the impression that most CodeProjectors here do not seem to like ORM's very much ...

                            J S 2 Replies Last reply
                            0
                            • M Marc Clifton

                              I'm curious -- are you doing anything with the database other than presenting it to the UI so the user can CRUD the data? As in, do you have actually have any business logic that actually does something internally with the data?

                              Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                              R Offline
                              R Offline
                              RickZeeland
                              wrote on last edited by
                              #26

                              Not so much business logic I think, but lots of logging data and presenting that in reports and charts to the user. In the past this application already had performance problems due to the massive number of queries, we switched from SQL Server to PostgreSQL for that reason.

                              1 Reply Last reply
                              0
                              • M Marc Clifton

                                I'm curious -- are you doing anything with the database other than presenting it to the UI so the user can CRUD the data? As in, do you have actually have any business logic that actually does something internally with the data?

                                Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                J Offline
                                J Offline
                                Jan Holst Jensen2
                                wrote on last edited by
                                #27

                                Marc Clifton wrote:

                                do you have actually have any business logic that actually does something internally with the data?

                                Indeed - and where is this business logic implemented ? If it is implemented in stored procedures (so all types of clients will have the same logic enforced), and you use views to decouple the clients from database dependencies and control client access, and you run an Oracle database - beware of the ORM. I sat on the sideline and watched a developer attempt to create a mostly auto-generated NHibernate-based C# WPF application against such an Oracle database. The schedule slipped again and again, and when the application was released it was a memory-hog, slow, and really hard to maintain. We already had a prototype non-ORM application written in a few days - but someone wanted a WPF app. But I can imagine that if you are interfacing directly to "dumb" tables with no server-side logic applied then I guess the situation will be different. Oh, and if your database is SQL Server - at least the developer in question never got Visual Studio to interpret the Oracle view layer correctly.

                                1 Reply Last reply
                                0
                                • R RickZeeland

                                  Well, if I understood him correctly he meant to reduce complexity and make programming more simple. I have to disagree on the performance point you make though, in the past the application he is working on proved to be problematic due to the massive amount of queries, this was one of the reasons to opt for PostgreSQL instead of SQL Server which we used before. SQL Server really struggled where PostgreSQL runs without any problems.

                                  J Offline
                                  J Offline
                                  Jorgen Andersson
                                  wrote on last edited by
                                  #28

                                  Why would the number of queries depend on the database? :doh:

                                  Wrong is evil and must be defeated. - Jeff Ello

                                  1 Reply Last reply
                                  0
                                  • J Jorgen Andersson

                                    Twenty tables, why bother? Sounds like changing for the sake of changing. If it was a new project, and mostly CRUD I'd go EF. Otherwise I'd handcrank it or use a lightweight micro-ORM. If performance is an issue of any kind whatsoever, don't do NHibernate. Here's[^] some benchmarks by Frans Bouma (of llblgen). Here's[^] an updated version the code he used. Take a look at the code and test for yourself.

                                    Wrong is evil and must be defeated. - Jeff Ello

                                    R Offline
                                    R Offline
                                    RickZeeland
                                    wrote on last edited by
                                    #29

                                    Thanks for the links ! My worst fears in regard to performance are confirmed, as NHibernate seems to be the ORM that performs the worst in Frans Bouma's test.

                                    J abmvA 2 Replies Last reply
                                    0
                                    • R RickZeeland

                                      Thanks, I'm afraid I'm one of those old farts haha :-\ Still I get the impression that most CodeProjectors here do not seem to like ORM's very much ...

                                      J Offline
                                      J Offline
                                      Jorgen Andersson
                                      wrote on last edited by
                                      #30

                                      RickZeeland wrote:

                                      Still I get the impression that most CodeProjectors here do not seem to like ORM's very much

                                      Because most old farts knows how to SQL. Slacker is right though, old farts don't like ORMs because they don't understand them. But don't forget that the opposite might be true as well, many (most?) advocates for ORMs don't understand SQL.

                                      Wrong is evil and must be defeated. - Jeff Ello

                                      C 1 Reply Last reply
                                      0
                                      • R RickZeeland

                                        At work a colleague has started using NHibernate, an ORM (Object-relational mapping), before this we only used hand-coded SQL routines. I wonder if this is a good choice, we are using VS2017, mainly C# and PostgreSQL. The database is fairly simple, only about 20 tables, but speed and performance are important factors.

                                        H Offline
                                        H Offline
                                        HobbyProggy
                                        wrote on last edited by
                                        #31

                                        I couldn't find a reason to change to ORM yet, so i'd say go the classical way.

                                        Rules for the FOSW ![^]

                                        if(!string.IsNullOrWhiteSpace(_signature))
                                        {
                                        MessageBox.Show("This is my signature: " + Environment.NewLine + _signature);
                                        }
                                        else
                                        {
                                        MessageBox.Show("404-Signature not found");
                                        }

                                        1 Reply Last reply
                                        0
                                        • R RickZeeland

                                          Thanks for the links ! My worst fears in regard to performance are confirmed, as NHibernate seems to be the ORM that performs the worst in Frans Bouma's test.

                                          J Offline
                                          J Offline
                                          Jorgen Andersson
                                          wrote on last edited by
                                          #32

                                          It is indeed. But you need to keep in mind that it is largely due to how the test is setup. Loading a large amount of data into a collection. That's not where EF or NHibernate excels. They are both defaulting to lazy loading the data. So if you mainly do CRUD you might not even notice that it's slower. I might add that my own mapper is even faster, but that's not an ORM.

                                          Wrong is evil and must be defeated. - Jeff Ello

                                          R 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups