本文介绍了为什么要使用Dapper?任何人都可以对Dapper与ADO.NET的优缺点进行评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解何时真正需要考虑使用Dapper.我也想了解比较Dapper与ADO.NET的利弊

I would like to understand on when would some one really need to think of using Dapper. Also i would like to understand the Pros and Cons of comparing Dapper Vs ADO.NET

推荐答案

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示例是由其他的精简程序库处理的)
  • 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?任何人都可以对Dapper与ADO.NET的优缺点进行评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:13