Dapper Tutorial Dapper.FastCrud Library

Overview

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.

  • It adds additional functionality, such as the ability to easily insert, update and delete multiple records in a single operation.
  • This allows you to easily query and update database tables without having to write any SQL code.

NuGet Installation

Dapper.FastCrud is available through NuGet: https://www.nuget.org/packages/Dapper.FastCrud

You can easily install this library by running the following command:

PM> Install-Package Dapper.FastCrud

Features

  • 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.

APIs

Once you installed this library then the following extension methods will automatically add to DbConnection:

  • Get
  • Find
  • Insert
  • Update
  • BulkUpdate
  • Delete
  • BulkDelete
  • Count

There is no configuration required and no need for extra coding. You can easily use these extension methods in your code.

var invoice = connection.Get(new Invoice { Id = 1 });
var list = connection.Find<Invoice>();

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>(new Invoice { Id = 2 });

var count = connection.Count<Invoice>();

You can find the detailed documentation here: https://github.com/MoonStorm/Dapper.FastCRUD/wiki

Support

This library is supported regularly and you will get your answers within the next few days. https://github.com/MoonStorm/Dapper.FastCRUD/issues