What is so great about ORM?

后端 未结 4 1011
花落未央
花落未央 2021-02-15 10:39

So I\'m having a head against the wall moment and hoping somebody can come help either remove the wall or stop my head from moving!!

Over the last 3/4 weeks I\'ve been i

4条回答
  •  感动是毒
    2021-02-15 11:09

    The biggest benefit of an ORM tool is that it will help you layer your application correctly. Most project nowadays use a Data Layer to connect to the database. You start from the ORM tool to produce classes that correspond to your database objects. Then you define an interface using these methods. All persistence code uses the methods of this interface. This way the business logic layer is only coupled to this higher-layer interface and needs to know nothing about the database. In fact there should be no dependency on ADO.NET or even NHibernate.

    Another advantage of ORM tools is that you de-couple your application from the database server. You could change the db engine and still use the same code. Also there isn't only the complexity of the SQL that the ORM hides from you. It can also help you with transactions logic and connection pooling.

    I'd say that for new projects an ORM tool is a necessity. For legacy projects it isn't so much beneficial, unless of course you have the time/money to start from scratch.

提交回复
热议问题