Dapper is an object mapper for .Net. As per stackoverflow definition, dapper is a micro-ORM, offering core parameterization and materialization services, but (by design) not the full breadth of services that you might expect in a full ORM such as LINQ-to-SQL or Entity Framework.
While working on one project in my company, I have come across this library and found that it is one of the fastest ORMs available in .net. For statistics, below is the result of select mapping over 500 iterations using different methods.
Method | Duration |
---|---|
Hand-coded (using a SqlDataReader) | 47ms |
Dapper ExecuteMapperQuery | 49ms |
ServiceStack.OrmLite (QueryById) | 50ms |
PetaPoco | 52ms |
BLToolkit | 80ms |
SubSonic CodingHorror | 107ms |
NHibernate SQL | 104ms |
Linq 2 SQL ExecuteQuery | 181ms |
Entity framework ExecuteStoreQuery | 631ms |
You can check more performance results of dapper at this GitHub link.
Let’s create a sample CRUD operation project with dapper as an ORM using ASP.NET MVC 4 and SQL Server.
You can add a dapper library to your project by downloading it from google code, or by using NuGet packages as shown below image.
I have created a class named person as shown below.
Also created database as shown below:
Below is the basic CRUD operations mapping with dapper.
I hope, this article is helpful to you in getting started with Dapper.