使用 ORM 的优缺点 [英] The advantages and disadvantages of using ORM

查看:31
本文介绍了使用 ORM 的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想讨论一下使用 ORM(例如 ADO.NET)的优缺点.

I would like to discuss the advantages and disadvantages of using ORM (such as ADO.NET).

  • 加速开发 - 无需重复的 SQL 代码.
  • 减少开发时间.
  • 降低开发成本.
  • 克服供应商特定的 SQL 差异 - ORM 知道如何编写供应商特定的 SQL,因此您不必这样做.
  • 开发人员在学习使用 ORM 编程时工作效率下降.
  • 开发人员无法理解代码实际在做什么 - 开发人员使用 SQL 可以更好地控制.
  • ORM 趋于缓慢.
  • ORM 无法与 SQL 查询竞争复杂查询.

总而言之,我认为使用 ORM 的优点(主要是减少执行重复性任务所需的时间)远远超过 ORM 的缺点,例如很难掌握.

In summary, I believe that the advantages of using an ORM (mainly the reduced time taken to perform repetitive tasks) are far outweighed by the disadvantages of ORM e.g. it's difficulty to get to grips with.

人们能否指出我哪里出错并提出任何进一步的优点/缺点.

Can people point out where I am going wrong and suggest any further advantages/disadvantages.

推荐答案

"ORM 无法与 SQL 竞争复杂查询的查询."

"ORM fail to compete against SQL queries for complex queries."

  • LINQ-SQL 和实体框架都允许复杂查询,甚至可以将 SQL 查询结果转换为对象.
  • 开发人员对代码实际上在做什么 -开发人员可以更好地控制使用SQL."

    "Developers loose understanding of what the code is actually doing - the developer is more in control using SQL."

    • 并非如此,如果您知道自己在做什么.SQL 分析器足以查看翻译后的 SQL 查询是什么.
    • ORM 趋于缓慢."

      • 是的,但延迟加载和一些智能选项可以使其几乎一样快.
      • 开发人员生产力下降,同时他们学习使用 ORM 进行编程."

        "Loss in developer productivity whilst they learn to program with ORM."

        • Hibernate 和实体框架可能需要时间来学习,但从长远来看,它们将节省开发时间.另一方面,LINQ-SQL 几乎不涉及学习曲线.
        • 我说,使用 ORM 但请记住这一点.

          I say, use ORM but keep this in mind.

          1. 设计查询并编写代码这将导致最少的数字与服务器的往返次数.它是往返的开销这需要时间.

          1. Design your queries and write code that will result in the least number of roundtrips with the server. It's the overhead taken for the roundtrip that takes up time.

          阅读其他经历人们已经与选定的ORM 在你深入挖掘之前.

          Read about the experiences other people have had with the selected ORM before you dig in too deep.

          始终将您的查询与实际在 SQL 中执行的服务器分析器.

          Always compare your queries with the actual ones being executed in SQL server profiler.

          您不会将 ORM 用于性能关键情况,就像您不会使用 .Net 或 Java 编写操作系统一样.选择前请考虑您的要求.即使您不使用 ORM,您最终也会通过重复大量代码或使用数据字典自己进行一些映射.为什么不使用 ORM 并知道如何使用它的选项使其几乎一样快?权衡利弊并做出选择.

          You wouldn't use an ORM for a performance critical situation same way you wouldn't use .Net or Java to write an operating system. Consider your requirements before choosing. Even if you don't use an ORM, you will end up doing some mapping yourself either via repeating a lot of code or by using a data dictionary. Why not use an ORM and know how to use its options to make it ALMOST as fast? Weigh up the advantages and disadvantages and make your choice.

          http://mikehadlow.blogspot.ca/2012/06/when-should-i-use-orm.html

          这篇关于使用 ORM 的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆