Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Dapper compare to ADO.NET?

When should Dapper be used instead of ADO.NET?

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?

like image 882
Divya Avatar asked Jun 22 '16 19:06

Divya


People also ask

Is Dapper better than entity framework?

Dapper is literally much faster than Entity Framework Core considering the fact that there are no bells and whistles in Dapper. It is a straight forward Micro ORM that has minimal features as well. It is always up to the developer to choose between these 2 Awesome Data Access Technologies.

When should I use Dapper?

If your project prefers writing stored procedures or writing native query instead of using a full-fledged ORM tools like EntityFramework or NHibernate then Dapper is obvious choice for you. Using Dapper, it is very easy to fire a SQL query against database and get the result mapped to C# domain class.

Which is better ADO.NET or entity framework Core?

The performance of ADO.Net is better than entity framework because ADO.Net is directly connected to the data source due to that it gives better performance than entity framework, whereas the performance of entity framework is less as compared to the ADO.Net as entity translate the LINQ queries to SQL first and then ...

Why is EF slower than Dapper?

But the answer to your question is Yes, Dapper is quicker than EF Core for reading data. And it probably always will be, because it is not a full blown ORM like EF Core. It is a simple object mapper and designed specifically to be quicker than EF Core for reading data.


1 Answers

Dapper is just a tool. What it does is:

  • make it trivially easy to correctly parameterize queries
  • make it trivially easy to execute queries (scalar, multi-rows, multi-grids, and no-results)
  • make it trivially easy to turn results into objects
  • very efficiently and quickly

What it doesn't do is:

  • generate a class model for you
  • generate queries for you
  • track objects and their changes so you can just call SubmitChanges() (or whatever)

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

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:

  • you want excellent raw execution performance with minimal overheads
  • you want to retain control over your SQL
  • you don't need or want the object-tracking features of a full-fat ORM

As for "vs ADO.NET":

  • 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)
like image 111
Marc Gravell Avatar answered Oct 19 '22 03:10

Marc Gravell