Dapper is another well known object-relational mapping (ORM) used in Microsoft .NET platform and owns the title of King of Micro ORM regarding speed. It is virtually as fast as using a raw ADO.NET data reader. Dapper extend the IDbConnection by providing useful extension methods to query your database. It is also an open source and distributed under dual license, either the Apache License 2.0 or the MIT License.
Dapper provides a framework to map a traditional relational database to an object-oriented model. It allows programmers to focus on the application business logic without worrying about relational data persistence-related programming tasks.
Dapper has the following key features:
- Operating directly on IDbConnection interface
- Speedy and high performance
- Fewer lines of code
- Object mapper
- Choice of static/dynamic object binding
- Easy handling of SQL query
- Multiple query support
- Support and easy handling of stored procedures
Dapper is a King of Micro ORM regarding performance, but a lot of essential features is missing for some application scenarios. The only way to achieve is either create code for this kind of scenario or use a library which fully or partially cover them.
There are a lot of libraries available which can enhance, improve, and extend the functionality which is not available in the core Dapper library, for example, basic CRUD operations, multi-mapping, manual mapping and convention based mapping, etc.
In this article, we will discuss the top 10 dapper libraries, or you can say the most useful libraries which are used in 2017.
DapperExtensions is a small library package which adds basic CRUD operations to Dapper. It also provides a predicate system for more advanced querying scenarios. DapperExtensions will keep your domain classes pure without any attributes or base class inheritance.
Once you installed this library then the following extension methods will automatically add to DbConnection:
2. Dapper.Contrib By johandanforth
Dapper.Contrib is a small library that you can add to your project which will extend IDbConnection interface with additional helper methods for CRUD operations, such as inserting, deleting, updating and getting records.
Dapper.Contrib can track your entities and identify if changes have been made.
If there is any change and you call the Update method, then it will generate the SQL and update only those properties that have been changed.
3. Dapper Plus By ZZZ Projects
Dapper.Plus is a small library that you can add to your project which will extend your IDbConnection and IDbTransaction interfaces with high efficient Bulk operations methods:
- Bulk Insert
- Bulk Update
- Bulk Delete
- Bulk Merge
Using this library, you can perform saving operations in the fastest way. It can be used with or without Dapper, and it is also compatible with all others Dapper packages.
For further details, you can visit http://dapper-plus.net/
4. Dapper.SimpleCRUD By ericdc
Dapper.SimpleCRUD is a small library package which adds basic CRUD operations to Dapper. Dapper.SimpleCRUD uses smart defaults without using attributes in your classes, but it can also be overridden as needed.
- The id column is used as a primary key by default, but you can override it with an attribute.
- By default, queries expect that table name is matching the class name, but you can override it with an attribute.
- Similarly, queries expect that column name is matching the property name, but you can also override it with an attribute.
5. Dapper.FluentMap By henkmollema
Dapper.FluentMap is a small library which allows you to fluently map properties of your domain classes to the database columns. This library functionality is similar to Entity Framework Fluent API and keeps your domain classes clean of mapping attributes.
There are two types of mapping supported in Dapper.FluentMap
- Manual Mapping
- Convention based mapping
For further details, you can visit https://github.com/henkmollema/Dapper-FluentMap/
6. Dapper.FastCrud By MoonStorm
Dapper.FastCrud is an extension for Dapper and is based on C# 6 and VB 14 essential features that have finally raised the simplicity of raw SQL constructs to acceptable maintenance levels.
It is recommended to use Visual Studio 2015 or an equivalent build environment when using features like string interpolation.
- This library package contains both .NET 4.5 and 4.6 DLLs, and one of them will be installed only based on the target framework selected in your project.
- Dapper.FastCrud can support SQLSever, LocalDB, SQLite, MySQL, and PostgreSQL, etc.
- Composite primary keys mapping.
- Multiple entity mappings are supported.
- Methods are available for CRUD operations.
- A simple SQL builder with alias support is provided, which can be used when manual SQL queries are unavoidable.
- Entity generation support is also provided by installing the NuGet package, Dapper.FastCrud.ModelGenerator.
For further details, you can visit https://github.com/MoonStorm/Dapper.FastCRUD/
7. Dapper.Mapper By dotarj
Dapper.Mapper is a small library which extends Dapper multi-mapping functionality. It allows you to map a single row to multiple objects. This library automatically figures out the relationships between the returned objects and automatically assigns them.
If you have used Dapper, then you will have an idea of writing mapping explicitly. Dapper.Mapper will handle the relationships between the returned objects automatically instead of writing mapping explicitly.
For further details, you can visit https://github.com/zzzprojects/EntityFramework.DynamicFilters
8. Dapper.SimpleSave By PaymentSense
Dapper.SimpleSave is a small library package which adds basic CRUD operations to Dapper. Dapper easily retrieve data from the database when a single object is involved, but when you are dealing with complex hierarchies, then dapper is not very helpfull. This is where Dapper.SimpleSave comes in and save complex objects to the database in a very simple way.
Dapper.SimpleSave need to decorate your domain classes with attribute, for example;
- Names of the tables and columns in a database.
- Which property represent primary key columns.
- The cardinality of relationships between tables etc.
For further details, you can visit https://github.com/Paymentsense/Dapper.SimpleSave/
9. Dapper.Rainbow By samsaffron
Dapper.Rainbow is a small library which contains an abstract class that you can add to your project and use as a base class for your Dapper classes to provide CRUD operations, such as inserting, deleting, updating and getting records.
Dapper.Rainbow is a wrapper for database interactions and will create SQL based on property names and type constraints.
10. Stove.Dapper By osoykan
- Stove.Dapper supports Dynamic Filters to filter automatically and default ISoftDelete or other user-defined filters.
- Dapper-EntityFramework works under same transaction and unit of work scope, if any exception appears in domain whole transaction will be rollback including Dapper's insert/deletes and EF's.
- Stove.Dapper also works with NHibernate under same transaction. Like EF transaction sharing.