Third Party Library - Dapper.Contrib
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 has the ability to 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.
Dapper.Contrib is available through NuGet: https://www.nuget.org/packages/Dapper.Contrib/
You can easily install this library by running the following command:
PM> Install-Package Dapper.Contrib
More information and documentation can be found at: https://github.com/StackExchange/Dapper/tree/master/Dapper.Contrib
Once you installed this library then the following extension methods will automatically add to DbConnection:
You can use these extension methods easily in your code.
Dapper.Contrib also allow mapping for special attributes using Data Annotations:
- Key: Specify the property as a key that is automatically generated by the database.
- ExplicitKey: Specify the property as a key explicitly which is not automatically generated by the database.
- Table: Specify the destination table name mapped to the entity.
- Write: Specify the property if it is writable or not.
- Computed: Specify the property that should be excluded from an update.
Unfortunately, there is no proper documentation available for this library, but you can get a little bit of help from: https://github.com/StackExchange/Dapper/tree/master/Dapper.Contrib
There is no support for composite key mapping.
Dapper.Contrib has Update extension method, and SQLiteConnection also exposes an Update event that clashes with each other. But you can easily resolve the clash by using any of the following ways:
- Pass a type parameter to Update method
- The other way is to call the Update method explicitly using SqlMapperExtensions.
This library is supported on a regular basis and you will get your answers within next few days. https://github.com/StackExchange/Dapper/issues