How to use dapper in .Net project

How to use Dapper in C#.Net

Dapper

Dapper is a micro ORM which make database operation simple using Models. It has capability to handle all type of databases.

The real charm of dapper is when you are working Model View pattern., l leaves that topic for another post.

How to use latest dapper ORM version with .Net project ?

Dapper require .Net Framework 4.7.2 or latter. Make sure the visual studio project support the Dapper or you can change the target Frame Work.

Open the Nuget manager and browse dapper and install the dapper and associated contrib extension.

Usage

We can use dapper by importing the Dapper library as follows.

using Dapper;
....
var sql ="select * from emp order by id";
using (SqlConnection con = <sql connection>)
{
  con.QueryFirst<Models.Employee>(sql);
                        
}

The above example is based on C#.Net. This will return a list of Employee objects, which can be used as bind source for a Data Gridview or a Combo control.

WordPress Posts on Dapper

The following Dapper post can be helpful for trouble shoot the problems.

OLEDB Date Error

OLEDB Insert Error

dapper

Write your comment