Basic CRUD operation using Dapper! - ByteScout
  • Home
  • /
  • Blog
  • /
  • Basic CRUD operation using Dapper!

Basic CRUD operation using Dapper!

Basic CRUD operation using Dapper!

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.

CRUD Dapper Tutorial

I have created a class named person as shown below.

Also created database as shown below:

Basic Operation with Dapper

Below is the basic CRUD operations mapping with dapper.

 

  1. Select operation

  1. Directly executing SQL statement

  1. Using stored procedures and pass argument

  1. Using dynamic parameters to pass arguments

  1. Returning output parameter from the stored procedure

I hope, this article is helpful to you in getting started with Dapper.

   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next