Press "Enter" to skip to content

c# Dapper Mvc Crud QueryWarehouse Part -3

What is Dapper
Dapper is simple/ micro ORM for the .NET world. It’s a NuGet library that can be added to any .NET project for database operations. ORM stands for Object Relational Mapping, meaning the entire database can be operated in terms of OO classes, Interfaces etc. ORM creates a “virtual database” in terms of classes and provides methods to work with those classes. Dapper is a Micro ORM as it’s architected to focus on the most important task of working with database tables instead of creating, modifying the database schema, tracking changes etc.

Hey, I never heard of Dapper, who uses it? Dapper is in production use at Stack Overflow. Really? Yes, Dapper was created by StackOverflow team to address their issues and open source it. Dapper used at Stack Overflow itself showcases its strength.

Why use Dapper
Dapper is a NuGet library, can be used with any .NET project. Quite lightweight, high performance.

Drastically reduces the database access code.

Focus on getting database tasks done instead of being full-on ORM. We cover more on this

Work with any database – SQL Server, Oracle, SQLite, MySQL, PostgreSQL etc.

For an existing database, using Dapper is an optimal choice.

Choosing Dapper over EF Core
EF Core and Dapper are both great technologies, but choosing Dapper would be based on your requirements and here are mine

Existing database with lots of stored procedure fetching a good amount of records.

Developer’s familiarity in working with raw SQL or ADO.NET.

The application mainly involves fetching for dashboards, reports.

Dapper uses underlying SQLConnection to work with the database, so easy it’s quite easy to use a different database at the same time i.e. I would use Dapper for SQL Server, Oracle or MySQL in the same application. In real world apps, we usually don’t deal with a single database.

Dapper is a NuGet library that can be added to any project. It extends the IDbConnection interface. The IDbConnection interface represents an open connection to data source implemented by the .NET framework. Every database provider extends this interface to for their database i.e. SQL Server, Oracle, MySQL etc. Dapper uses this connection, has its own set of methods to work with database independent of which database being chosen. This design goal of Dapper makes it easy to with any database almost in its own way. The following image shows the IDbConnection extended in the SQLConnection class (SQL Server provider).

Leave a Reply

Notify of