Dapper is opensource micro ORM framework that will help you access data from database in .Net projects. The project is maintained by stackoverflow community and hosted on GitHub
Usually database query return table which contains rows of information. In the object based programming world require data as class/objects. ORM help us to convert row into an object. It can also perform all CURD operations too.
The ORM can be utilized in Model-View-Model View pattern and it will help minimize the complexity of the code.
Dapper is not a database specific package. It can be used with any database (SQL Server,MySQL, MS Access etc). It uses a IDbConnection for performing operations.
It does not replacing anything at all, a simple example will explain the concept.
Dapper Object List example
using Dapper;
class Group
{
public int ID { get; set; }
public string g_name { get; set; }
public double g_dr_loc { get; set; }
public static List<Group> GetAll()
{
using (IDbConnection db = new System.Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["cstring"].ConnectionString))
{
return db.Query<Group>("select id,g_name from groups").ToList();
}
}
}
//calling
var groups=Group.GetAll()
Here in the example, the Group model’s GetAll() static method will query all the rows into List of Group(model) using the Dapper. Without dapper you have to use Linq or a loop to store the row as a list of objects.
You can see how Linq can be used to achieve this in the following posts