Dapper与ADO.NET相比如何? [英] How does Dapper compare to ADO.NET?

查看:91
本文介绍了Dapper与ADO.NET相比如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时应使用Dapper代替ADO.NET?

When should Dapper be used instead of ADO.NET?

我想了解ADO.NET上Dapper的优缺点.Dapper的优点是什么可以激发其使用?

I would like to understand the pros and cons of Dapper over ADO.NET. What are the advantages of Dapper that would motivate its use?

推荐答案

Dapper只是一个工具.做什么是:

Dapper is just a tool. What it does is:

  • 轻松轻松地正确设置查询参数
  • 轻松执行查询(标量,多行,多网格和无结果)
  • 将结果轻松转换为对象
  • 非常高效,迅速

所做的是:

  • 为您生成一个课程模型
  • 为您生成查询
  • 跟踪对象及其更改,因此您只需调用 SubmitChanges()(或其他任何方法)
  • generate a class model for you
  • generate queries for you
  • track objects and their changes so you can just call SubmitChanges() (or whatever)

原始dapper库不提供CRUD功能,但是贡献"附加包 提供基本的CRUD.

The raw dapper library doesn't provide CRUD features, but the "contrib" additional package does provide basic CRUD.

基本上,它不是完整的ORM,但是如果您只想运行查询而不必战斗 ORM或支付与ORM相关的间接费用,那就太好了.如果您不了解SQL,则可能不适合使用原始库(不过"contrib"应该没问题),但是很多人不仅知道 SQL,而且他们想>掌握SQL (而不是让ORM对尚未优化的意图进行一些解释,等等).

Basically, it isn't a full-weight ORM, but if you just want to run queries without having to fight an ORM, or pay the overheads associated with an ORM, it is pretty great. If you don't know SQL, the raw library probably isn't for you ("contrib" should be fine, though), but lots of people not only know SQL, but they want to be in control of the SQL (rather than letting the ORM come up with some interpretation of your intent that has not been optimized, etc).

总而言之,原因可能是:

To summarize, reasons might be:

  • 您希望以最小的开销获得出色的原始执行性能
  • 您想保留对SQL的控制
  • 您不需要或不需要全功能ORM的对象跟踪功能

相对于ADO.NET":

As for "vs ADO.NET":

  • 原始ADO.NET涉及很多的代码,还有很多需要记住的极端情况(dapper在内部进行处理而无需担心它们)
  • 但实际上并没有更快-dapper完成查询所需的操作后,就会进行很多元编程来存储和重用策略
  • 如果您使用的是原始ADO.NET中不提供的特定于提供程序的功能(例如,传递/获取 SqlGeometry 数据),则这些功能不是直接 在dapper中可用-您需要实现一个接口来告诉它如何处理场景,但这并不难(请注意,特定的 SqlGeometry 示例由其他的dapper库处理)
  • raw ADO.NET involves a lot more code to write and a lot of edge-cases to remember about (that dapper deals with internally without you needing to worry about them)
  • but it isn't actually faster - dapper does a lot of meta-programming to store and re-use strategies once it has done what it needs for your query
  • if you are using provider-specific features that aren't available in raw ADO.NET (for example, passing/fetching SqlGeometry data), those are not directly availalbe in dapper - you'd need to implement an interface to tell it how to handle your scenario, but that isn't hard (note that the specific SqlGeometry example is handled by an additional dapper library)

这篇关于Dapper与ADO.NET相比如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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