传统sql方法VS ORM [英] Traditional sql approach VS ORM

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

问题描述

我很沮丧地寻找这个更好的答案 -传统的System.Data.SqlClient方法或使用任何ORM(例如EF或Dapper) 我已经通过许多链接看到了许多比较,其中一些是:

I am really frustrated of searching this answer that what is better - Traditional System.Data.SqlClient approach or using any ORM like EF or Dapper I have seen many comparisons through many links, some are :

  1. https://github.com/StackExchange/dapper-dot-net

http://www.dontpaniclabs.com/blog/post/2014/05/01/speed-comparison-dapper-vs-entity-framework/

ORM与传统数据库查询他们的领域?

据我所知,手写传统sql代码的性能比任何其他方法都要好.但是我仍然想起,如果我们已经有了最好的方法,那么为什么要使用ORM?

One thing that I can understand that, hand written traditional sql code is better in performance than any other approach. but it is still hitting in my mind that if we already had the best approach then why ORMs?

是否仅因为我们要减少DataLayer代码?或者我们不想管理我们的数据库,并希望将所有内容都写在我们的C#代码中(首先是代码/数据)

Is it only because we want to reduce DataLayer code? or we dont want to manage our database and want to write everything there in our c# code (code/data first)

为什么引入EF,如果仅是代码管理成为问题,那么为什么以及我们如何损害查询执行的性能和速度,甚至ORM也有局限性.

Why EF was introduced, if only code management was the problem then, Why and how we are compromising with the performance and speed of query execution, even ORMs has limits.

请回答我的问题,并让我知道是否需要任何编辑.

Please answer my question and let me know if any edit is required.

我唯一关心的是网站的速度和性能.

My only concern is Speed and performance of my website.

谢谢.

推荐答案

我将根据我的经验尝试回答您的所有问题:

I'll try to answer all your questions based on my experience:

  1. 为什么要使用ORM? ORM在模型优先"方法中非常出色.当您拥有模型(您的类,对象,实体等)并决定将其保存到某个存储(例如DB)时.在这里,您采用合适的ORM并告诉它好,该类进入该表",依此类推.这样可以减少您的开发时间.当然,您在映射上有一些开销.但是,以我的经验,映射没有性能问题.我在所有其他部分(数据库查询,UI渲染,WCF等)中都遇到了性能问题,但没有ORM映射.因此,ORM减少了您的开发时间,微不足道地降低了性能.

ORM减少重复,降低复杂性并大大增加开发时间!

ORMs reduce duplicating, reduce complexity and highly increase development time!

用C#编写所有内容?部分-是的. ORM提供了强大的映射,因此几乎不可能犯一些愚蠢的错误,例如比较int和string,将null设置为不可为null的属性等等.因此,带有LINQ提供程序的ORM可为您的代码提供保护.

Writing everything in C#? Partly - yes. ORM offers strong mapping, so it's nearly impossible to make stupid mistakes like comparing int and string, setting null to not-nullable properties and so on. So, ORM with LINQ-provider offers protection of your code.

您对性能的担忧被夸大了.当然,EF(或其他ORM)比手写的SQL代码要慢.我相信,在99%的情况下,EF都会令您满意,并且此代码的​​自我保护和自我解释更加容易维护.

Your concerns about performance are exaggerated. Of course, EF (or other ORM) is slower than hand-written SQL code. I believe that in 99% of cases EF will satisfy you and it's much easier to maintain this code, it's self-protected and self-explained.

所以,不要看数字.他们在现实生活中没有任何共同之处. 如果您需要一些其他功能,我会尽力说明.

So, don't look at numbers. They don't have anything common with real life. If you need some additional, I'll try explain.

这篇关于传统sql方法VS ORM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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