DapperExtensions A Getting Started Tutorial for CRUD Operations
Overview
DapperExtensions is a small library package that 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.
- It provides a set of helper methods for mapping objects to and from database tables, as well as executing common SQL queries.
Why use DapperExtensions?
If you are using Dapper in your project, then the DapperExtensions library can make your life a lot easier.
- It provides a set of helper methods that eliminate the need to write boilerplate code when working with Dapper.
- In addition, it can help you avoid common SQL injection attacks by automatically parameterizing all your queries.
NuGet Installation
DapperExtensions is only available through NuGet: https://www.nuget.org/packages/DapperExtensions
You can easily install this library by running the following command:
PM> Install-Package DapperExtensions
More information can be found at: https://github.com/tmsmith/Dapper-Extensions
APIs
Once you installed this library then the following extension methods will automatically add to DbConnection
:
- Get
- GetList
- Insert
- Update
- Delete
- Count
You can use these extension methods easily in your code.
var invoice = connection.Get<Invoice>(1); var invoiceList = connection.GetList<Invoice>(); var identity = connection.Insert<Invoice>(new Invoice { Kind = InvoiceKind.WebInvoice, Code = "Insert_Single_1" }); invoice.Code = "Updated_invoice"; invoice.Kind = InvoiceKind.WebInvoice; var status = connection.Update<Invoice>(invoice); var isDeleted = connection.Delete<Invoice>(connection.Get<Invoice>(2)); var predicate = Predicates.Field<Invoice>(i => i.Kind, Operator.Eq, InvoiceKind.WebInvoice); var count = connection.Count<Invoice>(predicate);
Unfortunately, there is no proper documentation available for this library.
Support
Currently, this library is not supported.
Related Articles
ZZZ Projects